#1 2022-09-06 13:18:15

radexpol
Member
From: Poland, Krk
Registered: 2019-11-29
Posts: 116

Safe HttpServer constructor

TMyClass = class
  httpServer: TSQLHttpServer;
  list: TStringList;
  constructor Create;
end;
 
constructor TMyClass .Create;
begin
    list := TStringList.Create;
    HttpServer := TSQLHttpServer.Create('2080',[Server]);  -> exception port 2080 already in use
end;

I think that the constructor of TSQLHttpServer should be safe for object instancing, and does not start listening. Instead the "StartListening" method (like Indy TCPServer) could start the thread (bind and open listening port).

Offline

#2 2022-09-06 17:09:12

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,225
Website

Re: Safe HttpServer constructor

Use a try except block or create your own class calling it when  needing.

It is liké this since more than 10 years.

In mormot 2 this is slightly diverse.

Offline

Board footer

Powered by FluxBB