Newsgroups : Borland : borland.public.delphi.internet.winsock : 2006 Jun : Re: IdTCPServer
| Subject: | Re: IdTCPServer |
| Posted by: | "Remy Lebeau (TeamB)" (no.spam@no.spam.com) |
| Date: | Fri, 9 Jun 2006 11:24:45 |
"brandon" <someone@microsoft.com> wrote in message
news:4489aeea@newsgroups.borland.com...
> Is it possible to poll the clients periodically to see if
> they are alive, if not, then kill the thread gracefully.
Since Indy uses blocking sockets, the only way to detect a dead socket is to
read from, or write to, the socket and then check for an error.
A better way to handle dead clients is to implement timeouts and keepalives
in your own code. Make your client send a keep-alive command to the server
periodically, and have the server respond to it. If the server does not
receive the command in a given amount of time, just assume the client is
dead (even if it really sn't) and disconnect the socket. If the client does
not receive the response in a timely manner, then disconnect from the server
and reconnect.
This way, not only is the client actively telling the server "I'm still
here, don't lose me" periodically, but it also serves as a way for the
client to make sure the server is still alive as well.
Gambit