> To test that both ends of the socket are still alive & well, I use the
> following inside a class that wraps a standard Socket:
That class can't tell you any such thing. All those APIs tell you is
what methods you have called on your Socket at your end. They tell you
*nothing* about the state of the connection, and *nothing* about what
has happened at the other end.
There are only two ways of telling whether the other end of a TCP
connection is still there:
(a) try to read with a timeout set long enough that tripping it reliably
indicates that the sender has failed, or
(b) try to write to the socket. After you've filled enough send and
receive buffers you will eventually get an IOException or
SocketException "connection reset by peer" if the other end is closed or
aborted.
Bryan - 20 Dec 2006 16:13 GMT
I appreciate the input guys. I plan on gracefully catching the
EOFException and exiting the thread.
> garethcon...@mac.com wrote:
> > To test that both ends of the socket are still alive & well, I use the
[quoted text clipped - 13 lines]
> SocketException "connection reset by peer" if the other end is closed or
> aborted.