Newsgroups : Borland : borland.public.delphi.internet.winsock : 2008 Mar : How to limit number of concurrent clients in TServerSocket?
| Subject: | How to limit number of concurrent clients in TServerSocket? |
| Posted by: | "Bo Berglund" (bo.berglu..@telia.com) |
| Date: | Sun, 23 Mar 2008 11:55:58 |
I have an *existing* service application which I am trying to modify
and add some new functionality to. The application is really meant to
be used by a single client at a time, but there is no code implemented
to force this. Now the added functions really require the single
client operation so I need to figure out how to accomplish it.
But there seems to be no property on TServerSocket that can be used to
limit the number of connections, so what is the best way to do it?
I cannot switch it to Indy because this would be way too much work....
This is my (simplified) OnConnect code:
(FRemoteServer is the object holding all activity against the
instrumentation the application is handling)
procedure TRemoteServer.sckServerClientConnect(Sender: TObject;
Socket: TCustomWinSocket);
{Create the remote handler and assign the communication to it}
begin
try
Log('Client connected, IP=' + Socket.RemoteAddress + ' Host=' +
Socket.RemoteHost);
with TClientComm.Create(Socket, FRemoteServer) do
begin
OnDisconnect := Self.OnDisconnect;
FRemoteServer.ClientCallback := ClientCallback;
Log('Initializing new Client');
Initialize;
Log('Socket communication channel opened to ' +
Socket.RemoteAddress + ' Host=' + Socket.RemoteHost);
end;
except
on E: Exception do
begin
Log('Exception during client connect: ' + E.Message);
end;
end;
end;
I assume that it should be possible to somehow reject a connection if
the server already has an active connection running. Or can one stop
listening on the remote port while a client is connected?
/BoB