Dear All,
I have a very strange phenomenon on my embedded webserver.
It is a console application, which uses a common threaded webserver by the "Pure Hand Coding" way. The debug version is running locally on a Win10x64 system which is connected through a CISCO VPN to a remotely PGSQL database, running on a RPi4 in a corporate intranet. The release version is running on the same RPi as the PGSQL. In this latter case I can access the webserver through the VPN as well.
The served html pages are created in severeal ways: from spreadsheet's stream output; static .htlm files from the file system; or assembled by code.
The starting page is coming from a GET request, any other pages come from POST requests.
After starting the program, calling the
http://localhost:8080 (or
http://10.xxx.xxx.xxx:8080 in release) in the IE11 or in the Firefox browser, everything works fine.
The browsers load the start page, and I can navigate between pages which use the
request without problem.
However, things only work well, until I open the page in an Edge browser.
As soon as I open the
http://localhost:8080 from an Edge browser, the server doesn't respond to the IE11 and Firefox requests anymore, until the Edge request the same page as the IE or the Firefox.
Let's see an example!
1. We have 3 pages. The Firefox can navigate between them 1->2->3->1.
2. We start the Edge with page1.
3. Back to the Firefox we try to navigete to page 2, but it can't, until we choose the page 2 on Edge too.
When on the web page I push the button which fires the POST request several times, while the IE11 is waiting locked, I get an "
Error reading data from the socket" (code 10054) from the TFPHTTPConnection object on the application console.
I have no idea how to overcome this situation. I welcome any suggestion or help.
program webl;
{$mode objfpc}{$H+}
uses
{$IFDEF UNIX}
//{$IFDEF UseCThreads}
cthreads,
{$ENDIF}//{$ENDIF}
Classes, SysUtils, CustApp//, ...
{ you can add units after this };
var
Application: TMyApplication;
begin
Application:=TMyApplication.Create(nil);
Application.Title:='WebL';
Application.Run;
Application.Free;
end.
unit webserver;
{$mode delphi}
interface
uses
Classes, SysUtils,
fphttpserver, HTTPDefs, httpprotocol;
type
{ THTTPServerThread }
THTTPServerThread = class(TThread)
private
//FServer : TFPHTTPServer;
public
FServer : TFPHTTPServer;
OnRequest1: THTTPServerRequestHandler;
OnRequestError1 : TRequestErrorHandler;
OnAcceptIdle1: TNotifyEvent;
constructor Create(APort : Word; const OnRequest : THTTPServerRequestHandler; const OnRequestError : TRequestErrorHandler; const OnAcceptIdle: TNotifyEvent);
procedure Execute; override;
procedure DoTerminate; override;
end;
implementation
constructor THTTPServerThread.Create(APort: Word; const OnRequest: THTTPServerRequestHandler; const OnRequestError : TRequestErrorHandler; const OnAcceptIdle: TNotifyEvent);
begin
OnRequest1:=OnRequest;
OnRequestError1:=OnRequestError;
OnAcceptIdle1:=OnAcceptIdle;
FServer:=TFPHTTPServer.Create(Nil);
FServer.Port:=APort;
FServer.OnRequest:=OnRequest;
FServer.OnRequestError:=OnRequestError;
inherited Create(False);
end;
procedure THTTPServerThread.Execute;
begin
try
FServer.Active:=True;
finally
FreeAndNil(FServer);
end;
end;
procedure THTTPServerThread.DoTerminate;
begin
inherited DoTerminate;
FServer.Active:=False;
end;
end.
unit webmodul;
{$mode delphi}
interface
uses
Classes, SysUtils, Math, //StdCtrls,
//Graphics,
fphttpserver, HTTPDefs, httpprotocol, fphttpapp, fpwebfile, webserver, fpmimetypes,
htmlconttype, {...};
TWebModul = class(TObject)
private
FServer1 : THTTPServerThread;
procedure DoHandleRequest (Sender: TObject; var ARequest: TFPHTTPConnectionRequest; var AResponse : TFPHTTPConnectionResponse);
procedure DoHandReqError(Sender : TObject; E : Exception);
procedure DoAcceptIdle (Sender: TObject);
protected
{...}
public
constructor Create(AdatModule: TDataModule1);overload;
destructor Destroy; override;
published
end;
implementation
{ TWebModul }
constructor TWebModul.Create(AdatModule: TDataModule1); //AdatModule is the database related unit
begin
inherited Create;
FServer1 := THTTPServerThread.Create(AdatModule1.WebPort,DoHandleRequest,DoHandReqError,DoAcceptIdle); //AdatModule1.WebPort:=8080
end;
{...}
//***********************************************************************************
procedure TWebModul.DoHandleRequest(Sender: TObject; var ARequest: TFPHTTPConnectionRequest; var AResponse: TFPHTTPConnectionResponse);
var
file1: TMemoryStream;
begin
file1 := TMemoryStream.Create;
{...}
if {ARequest.ContentFields.Values=} true
then
begin
fromspreadsheet(file1); //from the spreadsheet unit
AResponse.FreeContentStream:= true;
AResponse.ContentStream :=file1;
AResponse.ContentType:=htmlcontenttype('.html'); //:='text/html;charset=utf-8'
AResponse.Code:=200;
AResponse.SendContent;
end;
{...}
file1.Free;
end;