Recent

Author Topic: WINCE / fphttpserver "Listening on port #1 failed, error: 10022"  (Read 3323 times)

sanmiolade

  • New Member
  • *
  • Posts: 19
WINCE / fphttpserver "Listening on port #1 failed, error: 10022"
« on: September 16, 2013, 01:31:02 pm »
Hello All,


 These are my problems....I am trying to build a Embedded WebServer for my WINCE Device so
 my users can change the device settings via a browser.

 I built a Simple WebServer, it works on my Windows Dev Computer
 but when I move the same code to my WINCE it gives the "Listening on port #1 failed, error: 10022"

Please I need a Solution

*** MY CODE IS BELOW ****
unit Unit1;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils,EmbeddedWebServerClass, FileUtil, Forms,LResources, Controls, Graphics, Dialogs, StdCtrls,fpwebfile,fphttpserver;

type

  { TForm1 }

  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Memo1: TMemo;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { private declarations }
  public
    { public declarations }
    procedure HandleWebServerRequest(Sender: TObject; var ARequest: TFPHTTPConnectionRequest; var AResponse: TFPHTTPConnectionResponse);
  end;

var
  Form1: TForm1;
  myWebServer :EmbeddedWebServer;
  FServer : TFPHTTPServer;
implementation

{$R *.lfm}

{ TForm1 }

procedure TForm1.FormCreate(Sender: TObject);
begin

    self.Position:= poDesktopCenter;
end;

procedure TForm1.Button1Click(Sender: TObject);


begin
    Memo1.Lines.Add('Starting server');
    FServer:=TFPHTTPServer.Create(self);
    FServer.Port:=8081;
    FServer.OnRequest:=@HandleWebServerRequest;
    Memo1.Lines.Add('Done Starting server');

end;

procedure TForm1.Button2Click(Sender: TObject);
begin
    Memo1.Lines.Add('Starting Active '+ inttostr(FServer.Port));
  FServer.Active := true;;
end;


procedure TForm1.HandleWebServerRequest(Sender: TObject; var ARequest: TFPHTTPConnectionRequest; var AResponse: TFPHTTPConnectionResponse);

begin

      memo1.Lines.add(ARequest.URL);
end;

end.

white_zombie

  • New Member
  • *
  • Posts: 12
Re: WINCE / fphttpserver "Listening on port #1 failed, error: 10022"
« Reply #1 on: September 16, 2013, 05:46:30 pm »
Hi,

I suffered this error and your post remember me that I should open a bug report about it.

The problem is inside TFPCustomHttpServer, the function "listen" is called twice and this produced an error in Wince but not on Windows and Linux.

To be precise, the procedure "StartServerSocket" (see below) call FServer.Listen and inside procedure FServer.StartAccepting is called again.

Code: [Select]
procedure TFPCustomHttpServer.StartServerSocket;
begin
  FServer.Bind;
  FServer.Listen;
  FServer.StartAccepting;
end;

So, you need to modify the class TFPCustomHttpServer by yourself or wait for this to be resolved by the FPC team.

Best Regards.

sanmiolade

  • New Member
  • *
  • Posts: 19
Re: WINCE / fphttpserver "Listening on port #1 failed, error: 10022"
« Reply #2 on: September 16, 2013, 07:38:45 pm »
So kindly tell me what EXACTLY I am supposed to do .

Will I comment Code ??....if so which Code do I comment ??

Thanks

sanmiolade

  • New Member
  • *
  • Posts: 19
Re: WINCE / fphttpserver "Listening on port #1 failed, error: 10022"
« Reply #3 on: September 17, 2013, 06:14:25 am »
Thanks Guys it WORKED

What I did was to Comment out the

procedure TFPCustomHttpServer.CreateServerSocket;
begin
  FServer.Bind;
 // FServer.Listen;  <---- COMMENT THIS OUT
  FServer.StartAccepting;
end;