Michael C. Toren on Mon, 16 Aug 1999 16:28:18 -0400 (EDT)


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [Plug] sockets


> Please forgive me for the nonlinux specific post.  (please please please)
> 
> How does one know a client socket has dropped off in C++.  Write to it and
> catch the "broken pipe" exception?

Essentially.  There is a SO_KEEPALIVE option which you can specify, which
I believe will periodically send an empty packet to ensure that the remote
end is still there, but by default this is only done every two hours or
so.  If you're writing both the client and server ends of the application,
it's probably best to include a simple PING / PONG type protocol riding on
top of the socket to determine if the peer is still connected.

W. Richard Stevens's books on the subject are highly recommended.  Also,
http://kipper.york.ac.uk/~vic/sock-faq/html/unix-socket-faq-2.html is a
very good source.

-mct