Socket communication issues.

Discussion in 'Java' started by k2, Feb 25, 2007.

  1. k2

    k2 Guest

    Hello,
    Scenario... Client connects to server socket, no problem sending
    transmission packs back and forth...
    Somewhere during this communication the server socket closes for any
    number of reasons.
    Currently, the client has no idea this event has happened, so it will
    attempt to write to the outputstream and then wait for an excruciatingly
    long time for the reply on the inputstream before finally timing out.
    Shouldn't there be some indication that the socket has died on the
    server? Client socket check for isConnected is still true after this
    event, so it carries on as if there's something listening on the other
    end when in fact it isn't. Is there some basic cleanup that the server
    should be performing during its shutdown process in order to cleanly
    sever the communication?

    thanks,
    K2

    --
    *****************************************
    Please remove the killspam portion of
    my return address if replying directly
    *****************************************
    k2, Feb 25, 2007
    #1
    1. Advertising

  2. k2

    Guest

    On Feb 24, 8:41 pm, k2 <> wrote:
    > Hello,
    > Scenario... Client connects to server socket, no problem sending
    > transmission packs back and forth...
    > Somewhere during this communication the server socket closes for any
    > number of reasons.
    > Currently, the client has no idea this event has happened, so it will
    > attempt to write to the outputstream and then wait for an excruciatingly
    > long time for the reply on the inputstream before finally timing out.
    > Shouldn't there be some indication that the socket has died on the
    > server? Client socket check for isConnected is still true after this
    > event, so it carries on as if there's something listening on the other
    > end when in fact it isn't. Is there some basic cleanup that the server
    > should be performing during its shutdown process in order to cleanly
    > sever the communication?


    isConnected will return true any time after connect() has been
    called. Don't use it to check if the socket is actually usable -- the
    ONLY way to determine that is to try to use it.

    Each side of a TCP conversation has to close the socket separately: if
    the server closes its half, the client is still allowed, by the TCP
    spec, to send data; the server may not send any data back because its
    half is closed. You need to design shutdowns into your protocol.

    For example, IRC clients send QUIT :reason and then close their half
    of the socket, and the IRC server responds to QUIT by closing its half
    of the connection. HTTP 1.0 clients send an HTTP request and close
    their half immediately, and the server closes its half at the end of
    the response.
    , Feb 25, 2007
    #2
    1. Advertising

  3. On Sat, 24 Feb 2007 20:41:15 -0800, k2 wrote:
    > Somewhere during this communication the server socket closes for any
    > number of reasons. Currently, the client has no idea this event has
    > happened, so it will attempt to write to the outputstream and then
    > wait for an excruciatingly long time for the reply on the
    > inputstream before finally timing out.


    Do you mean the server closed the Socket, or the ServerSocket? The
    ServerSocket has no relevance for existing connections, so closing it
    should have no effect on the client whatsoever.

    If the server really has closed the Socket, then the client's
    subsequent attempt to read or write will cause EOF to be indicated
    with either an exception or a special return value (which depends on
    the specific methods used).

    Post a simple code example that shows the behaviour you're describing.

    > Shouldn't there be some indication that the socket has died on the
    > server? Client socket check for isConnected is still true after this
    > event, so it carries on as if there's something listening on the other
    > end when in fact it isn't.


    isConnected() and friends don't tell you anything about the underlying
    connection, they only tell you what methods you've called on the
    Socket object itself.

    /gordon

    --
    [ don't email me support questions or followups ]
    g o r d o n + n e w s @ b a l d e r 1 3 . s e
    Gordon Beaton, Feb 25, 2007
    #3
  4. Hi K2,

    > Currently, the client has no idea this event has happened, so it will
    > attempt to write to the outputstream and then wait for an excruciatingly
    > long time for the reply on the inputstream before finally timing out.


    I found setSoTimeout (won't help your writes) and setKeepAlive but no
    tcpProbeIdle tcpDropIdle or soFullDuplexClose. Curious.

    The demo example I'm currently knocking up doesn't check for -1 on the Write
    but nonetheless it completes immediately when I kill the server process. And
    the subsequent Read reports an immediate error. My server is not Java and I
    do have the FullDuplexClose option set their.

    Regards Richard Maher

    "k2" <> wrote in message
    news:...
    > Hello,
    > Scenario... Client connects to server socket, no problem sending
    > transmission packs back and forth...
    > Somewhere during this communication the server socket closes for any
    > number of reasons.
    > Currently, the client has no idea this event has happened, so it will
    > attempt to write to the outputstream and then wait for an excruciatingly
    > long time for the reply on the inputstream before finally timing out.
    > Shouldn't there be some indication that the socket has died on the
    > server? Client socket check for isConnected is still true after this
    > event, so it carries on as if there's something listening on the other
    > end when in fact it isn't. Is there some basic cleanup that the server
    > should be performing during its shutdown process in order to cleanly
    > sever the communication?
    >
    > thanks,
    > K2
    >
    > --
    > *****************************************
    > Please remove the killspam portion of
    > my return address if replying directly
    > *****************************************
    Richard Maher, Feb 25, 2007
    #4
    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. Laszlo Nagy
    Replies:
    1
    Views:
    4,758
    Mark Wooding
    Jan 27, 2009
  2. Jean-Paul Calderone
    Replies:
    0
    Views:
    942
    Jean-Paul Calderone
    Jan 27, 2009
  3. Laszlo Nagy
    Replies:
    0
    Views:
    525
    Laszlo Nagy
    Feb 1, 2009
  4. Steve Holden
    Replies:
    0
    Views:
    643
    Steve Holden
    Feb 1, 2009
  5. Steve Holden
    Replies:
    1
    Views:
    698
Loading...

Share This Page