detecting a socket reset

Discussion in 'Java' started by Gordon Beaton, Nov 9, 2004.

  1. On 9 Nov 2004 05:06:23 -0800, Harvey Tate wrote:
    > I am writing some code to read data from a socket. The server side
    > socket can reset and I am wondering how I detect the reset? Is there
    > an non-evasive way of detect a socket diconnect? I know I can do a
    > read and then catch the subsequent exception however is there a way
    > to detect the disconnect without doing the read?


    Yes, you could attempt to write. Those are your two alternatives.

    On the other hand, consider why you care about the disconnect, unless
    you actually need to read or write?

    Assuming that you really do need to know as early as possible, you
    could define your application protocol to include a heartbeat message
    that the remote should respond to in a timely manner, and send that
    periodically when the connection is idle. Others may suggest the
    SO_KEEPALIVE socket option, however it's poorly suited for this.

    /gordon

    --
    [ do not email me copies of your followups ]
    g o r d o n + n e w s @ b a l d e r 1 3 . s e
    Gordon Beaton, Nov 9, 2004
    #1
    1. Advertising

  2. Gordon Beaton

    Harvey Tate Guest

    I am writing some code to read data from a socket. The server side
    socket can reset and I am wondering how I detect the reset? Is there
    an non-evasive way of detect a socket diconnect? I know I can do a
    read and then catch the subsequent exception however is there a way to
    detect the disconnect without doing the read?

    Thanks
    Harvey Tate, Nov 9, 2004
    #2
    1. Advertising

  3. Gordon Beaton

    Harvey Tate Guest

    thanks gordon - I'll discuss this with the guys at the other end of the socket!
    Harvey Tate, Nov 10, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Harvey Tate

    detecting a socket reset

    Harvey Tate, Nov 9, 2004, in forum: Java
    Replies:
    4
    Views:
    756
    Sudsy
    Nov 10, 2004
  2. Laszlo Nagy
    Replies:
    1
    Views:
    4,807
    Mark Wooding
    Jan 27, 2009
  3. Jean-Paul Calderone
    Replies:
    0
    Views:
    960
    Jean-Paul Calderone
    Jan 27, 2009
  4. Laszlo Nagy
    Replies:
    0
    Views:
    542
    Laszlo Nagy
    Feb 1, 2009
  5. Steve Holden
    Replies:
    0
    Views:
    655
    Steve Holden
    Feb 1, 2009
Loading...

Share This Page