Karjala wrote:
I'm writing a simple client-server application, and I'm trying to find a way to tell if the other end of an open TCP connection has gone offline.

If the other side has closed its end of the connection, you detect this by reading from the socket and receiving EOF (0 bytes read), or writing to the socket and getting SIGPIPE.

If the other side has crashed (not just process terminated, but server itself has crashed), or the network has gone down between the two, you either need to use some kind of timeout (based on what a "reasonable" response time would be), or use the SO_KEEPALIVE socket option. With the latter, the kernel will probe the remote side after some period of inactivity and shutdown the connection if the other side doesn't respond.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to