Is my socket open?  
Author Message
Chase Preuninger





PostPosted: 2008-4-19 1:49:00 Top

java-programmer, Is my socket open? What is the most reliable way to tell if a socket is sill connected?
 
Peter Duniho





PostPosted: 2008-4-19 2:03:00 Top

java-programmer >> Is my socket open? On Fri, 18 Apr 2008 10:48:37 -0700, Chase Preuninger
<email***@***.com> wrote:

> What is the most reliable way to tell if a socket is sill connected?

The only reliable way is to try to send something. With TCP, unless the
socket has been closed gracefully (in which case you'll get whatever "end
of stream" indication is appropriate for the class you're using, be that a
return value of -1 or 0 for example), no interruption in the connection
can be detected unless the side that wants to detect the interruption
tries to send something.

I'm tempted to use the same abusive tone here that you've used on others,
but...well, it's only a temptation. I can resist. :)

Pete
 
Eric Sosman





PostPosted: 2008-4-19 2:27:00 Top

java-programmer >> Is my socket open? Chase Preuninger wrote:
> What is the most reliable way to tell if a socket is sill connected?

Move some data through it.

--
email***@***.com
 
 
Daniel Pitts





PostPosted: 2008-4-21 2:35:00 Top

java-programmer >> Is my socket open? Eric Sosman wrote:
> Chase Preuninger wrote:
>> What is the most reliable way to tell if a socket is sill connected?
>
> Move some data through it.
>
Specifically, if your application-level protocol supports some sort of
ping/pong handshake, use it as appropriate. You can also have some sort
of time-out, where if you haven't had any activity in /n/ minutes,
assume the connection is dead.

--
Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>