El 4/6/20 a les 12:04, Luca Olivetti via lazarus ha escrit:
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;

Oh, and I had to do some more overriding so that the response could have a reference to the calling thread (needed if I want to use synchronize).

Bye

--
Luca Olivetti
Wetron Automation Technology http://www.wetron.es/
Tel. +34 93 5883004 (Ext.3010)  Fax +34 93 5883007
--
_______________________________________________
lazarus mailing list
lazarus@lists.lazarus-ide.org
https://lists.lazarus-ide.org/listinfo/lazarus

Reply via email to