07-08-2020, 03:53 PM
Remy, thanks for your help!
I got the tests running fine now so I am going to replace the TServerSocket based code with the new connection based on TIdTCPServer.
I then also think I need to address the case when the server is shut down with clients connected...
But I am not sure how to handle that precisely...
Here is parts of what I have at the moment:
I got the tests running fine now so I am going to replace the TServerSocket based code with the new connection based on TIdTCPServer.
I then also think I need to address the case when the server is shut down with clients connected...
But I am not sure how to handle that precisely...
Here is parts of what I have at the moment:
Code:
constructor TRemoteServer.Create;
begin
//Create idTCPServer
FServer := TIdTCPServer.Create(NIL);
FServer.Active := False;
//Allow only 2 connections
FServer.MaxConnections := 2;
//Define the callback functions
FServer.OnConnect := ServerConnect;
FServer.OnDisconnect := ServerDisconnect;
FServer.OnExecute := ServerExecute;
FServer.OnStatus := ServerStatus;
FClientPort := GUEST_CLIENT_PORT;
end;
destructor TRemoteServer.Destroy;
begin
if FServer.Active then
begin
if ClientCount > 0 then
begin
//Need to disconnect the clients so they get the message....
//What to do here?
end;
FServer.Active := false;
end;
FServer.Free;
inherited Destroy;
end;
function TRemoteServer.ClientCount(): integer;
var
nClients : integer;
begin
try
//get number of connected clients
nClients := FServer.Contexts.LockList.Count;
finally
FServer.Contexts.UnlockList;
end;
Result := nClients;
end;