Newsgroups : Borland : borland.public.delphi.internet.winsock : 2008 Mar : Re: How to limit number of concurrent clients in TServerSocket?

www.cryer.info
Managed Newsgroup Archive

Re: How to limit number of concurrent clients in TServerSocket?

Subject:Re: How to limit number of concurrent clients in TServerSocket?
Posted by:"Bo Berglund" (bo.berglu..@telia.com)
Date:Wed, 26 Mar 2008 23:01:05

On Wed, 26 Mar 2008 14:37:31 -0700, "Remy Lebeau \(TeamB\)"
<no.spam@no.spam.com> wrote:

>
>"Bo Berglund" <bo.berglund@telia.com> wrote in message
>news:qaelu3lvhja5sv7c9tlo6p2rmtccs57ve3@4ax.com...
>
>> Yes, I am deliberately taking it stepwise and since I soon
>> discovered that the active connections incremented I did
>> not put in the close() call.
>
>The count is increasing because you are not closing the connections.

When I try to close the socket inside the OnSocketEvent of the socket
supplied by the server socket OnConnect it starts an eternal loop of
calls to OnSocketEvent.
So I introduced a timer to move the socket close away from the
OnSocketEvent handler, but the active connections seem to increment
anyway (see separate post).
>
>> As soon as the first client disconnected noone would be
>> able to connect at all
>
>Yes, they would, under normal situations.  The only way it wouldn't work is
>if you are preventing the server from operating properly in the first place.

My problem is that apparently the server is *not* operating "properly"
and I am trying desperately to find out how to make it behave...
But given that the activeconnections do increment like this it is
really no way a client could connect anymore if the connection is
stopped cold when the activeconnections is > 1, right. The priority
must be to get it to decrement the connections on disconnect.
>
>> since the active connections never decrement.
>
>Yes, it will, when the server is allowed to operate properly.
>
>> So my code is now aimed at finding out what is going on when clients
>> disconnect.
>
>Are you saying that the OnClientDisconnect event NEVER fires?  If so, then
>your app is definately preventing the server from operating correctly.  What
>is your exact setup?

I have implemented this (been there all the time):

procedure TSSRemoteServer.sckServerClientDisconnect(Sender: TObject;
Socket: TCustomWinSocket);
begin
  FRemoteServer.ClientCallback := NIL;
  LogServer.StdLog('sckServerClientDisconnect: Client disconnect ' +
Socket.RemoteAddress);
end;

I *never* see any logging from this event so I assume that it is never
called. But why this is so I have no clue. I am not a TCP/IP expert by
far, I just want to use the Delphi components to create the
client/server system for handling the remote instrumentation....

What exactly do you mean by "your exact setup"???

The design of the system is really simple:

1. A "normal" server application using a TServerSocket component
placed on the form.

2. In the ClientConnect event handler I create a client communications
handler object, which is passed the Socket: TCustomWinSocket pointer
from the call parameters.

3. The handler assigns OnSocketEvent and OnSocketError handlers to the
passed socket and also saves it in a local field variable FSocket.

4. All further communication to/from the client is now handled via the
OnSocketEvent handler, including the disconnect.

5. When disconnect is fired I originally just logged and then freed
self, but I also tested now to isolate this from the event handler by
moving it into a timer event, where I also tried to close the FSocket
socket. No change in behaviour...


/BoB

Replies:

In response to:

www.cryer.info
Managed Newsgroup Archive