[Lazarus] fpWeb and server-sent events
Luca Olivetti
luca at wetron.es
Thu Jun 4 12:04:26 CEST 2020
El 4/6/20 a les 11:48, Michael Van Canneyt ha escrit:
>> It turns out I can with some careful, or reckless ;-), overriding.
>>
>> https://paste.ubuntu.com/p/CdHfc7BTHB/
>
> Haha, very nice job :-)
>
> I'll see if I can integrate this in the HTTPServer request/response.
>
> It won't work in fastCGI/CGI of course, but if we can make it available
> in a
> http application, why not...
I think that approach (take over the socket from the response) could be
useful in more cases, e.g. streaming content, websockets, etc.
As you say it has to be a stand-alone/embedded server and probably it
only works when it's threaded (due to the connection being kept active
for an indeterminate time), but that's better than nothing.
Now, I have another problem: if the server cannot bind to the port it
throws an exception, but then I cannot try again, I have to destroy and
recreate the server, e.g. this doesn't work (the second call to
FServer.Run return immediately):
FServer:=TSseServerHandler.Create(nil);
FServer.Port:=8080;
FServer.Threaded:=true;
while not terminated do
try
FServer.Run;
except
on E:Exception do
begin
writeln(E.Message);
sleep(1000);
FServer.Terminate;
end;
end;
this does (but I don't like it)
while not terminated do
try
FServer:=TSseServerHandler.Create(nil);
FServer.Port:=8080;
FServer.Threaded:=true;
FServer.Run;
except
on E:Exception do
begin
writeln(E.Message);
sleep(1000);
FServer.Free;
end;
end;
Bye
--
Luca Olivetti
Wetron Automation Technology http://www.wetron.es/
Tel. +34 93 5883004 (Ext.3010) Fax +34 93 5883007
More information about the lazarus
mailing list