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:Fri, 28 Mar 2008 00:07:06

On Thu, 27 Mar 2008 03:13:40 -0700, "Remy Lebeau \(TeamB\)"
<no.spam@no.spam.com> wrote:

>
Follow-up:
I have now implemented the socket data handling entirely within the
TServerSocket's own events and I am not messing with implementation of
event handlers inside of the Comm object.
Now I get the behaviour you have indicated and the ActiveConnection
can be used to determine if I should allow a client connect or not.

However, I have thought of a scenario where this may not work to my
advantage:

Imagine that the server has a connected client and then for some
reason the network stops working (power fail on the DSL router or
similar, or maybe just a failing network cable).
Now, how can the server know that this has happened and dispose of the
Active connection?

If it does not detect this then when the network connectivity is
re-established it will be impossible to connect because the
ActiveConnections will now be >1 and I have in effect a totally
unreachable server....

Question: Will this happen?

If the answer is yes then maybe I must add a timer or similar on the
server application that can be used to check if there has been any
activity from the client within a set time. The ClientRead could set a
timestamp like so:
FActivityTime := GetTickCount

Then in the timer event I could check the time since the last activity
and close the socket if this is the case.

If GetTickCount - FActivityTime > MaxIdleTime then
begin
  What do I do here? I want to disconnect the client, but I
  don't have the handle to the socket so Socket.Close won't work.
  The thing I want is to restart the listening and get rid of any
  lingering connection the server thinks it has.
end;

Is there a smarter way to make sure that the server is getting rid of
nonworking connections in a reliable way?


/BoB

Replies:

In response to:

www.cryer.info
Managed Newsgroup Archive