Newsgroups : Borland : borland.public.delphi.internet.winsock : 2008 Mar : Re: How to limit number of concurrent clients in TServerSocket?
| Subject: | Re: How to limit number of concurrent clients in TServerSocket? |
| Posted by: | "Remy Lebeau (TeamB)" (no.spam@no.spam.com) |
| Date: | Thu, 27 Mar 2008 16:22:39 |
"Bo Berglund" <bo.berglund@telia.com> wrote in message
news:349ou3h9anpll3oss8hiq2slco40anmpkp@4ax.com...
> 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?
The connection will time out internally eventually, allowing the OS to issue
a disconnect event to TServerSocket so it can clean up its tracking of the
connection properly.
> 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....
When the network is restored, the OS should be detecting the now-invalid
connection and reset it.
> 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.
That is a good idea to implement in general anyway. Even if the network
does not go down, the client may still go silent on its end. The connection
will still be valid, but no data comes from it.
> If GetTickCount - FActivityTime > MaxIdleTime then
You do know that using tick counts like that will not work correctly after
49.7 days, right? You would be better off using a TDateTime instead.
> What do I do here? I want to disconnect the client,
> but I don't have the handle to the socket
Yes, you do - TServerSocket.Socket.Connections[0]
> so Socket.Close won't work.
Yes, it will.
Gambit