6 Replies Latest reply: Jan 16, 2011 2:15 PM by 802316 RSS

    Problem detecting network inturruptions

    831532
      In have a TCP socket based client and server application. After client application get connected with server both client and server start listening on the inputstream of the socket wrapped by buffered inputstream.If either application stops other side trows an socket exception at bufferedreader.read(byte[] b, int off, int len). but the problem is when those two applications are in separate machines and when the network cable between those two machines is unplugged by hand either application cant detect it(No exception is thrown)until it tries to send some data. what is the reason for this behavior? Is there any way to detect that with out using an application level pulse messages between client and server nodes.
        • 1. Re: Problem detecting network inturruptions
          EJP
          That's how TCP works. There are only two solutions: a read timeout (Socket.setSoTimeout()) or an application-level ping message.
          • 2. Re: Problem detecting network inturruptions
            831532
            Thanks a lot for your reply.
            EJP wrote:
            That's how TCP works.
            I don't have in depth knowledge regarding how TCP works. So what I'm not clear about the above is what is the different between one side closing the application and being unreachable due to network issue? is there any message sent to the counter party when the process which created and using the the socket abruptly shuts down at one end.
            • 3. Re: Problem detecting network interruptions
              tschodt
              TCP 'allows' you to unplug the network (*) and plug it back in after a cigarette
              and if neither end attempted to transmit data while the network was unplugged
              the TCP socket still exists.
              (*) assuming the TCP stack does not detect and react to media disconnect.
              user13752858 wrote:
              ... what is the different difference between one side closing the application and being unreachable due to network issue?
              When a TCP socket is closed
              FIN is sent or possibly RST if there is data in the TCP buffers.
              is there any message sent to the counter party when the process which created and using the the socket abruptly shuts down at one end.
              If a process terminates without closing TCP sockets
              the TCP stack probably tidies up each TCP socket and
              sends RST to the remote or possibly FIN if there is no data in the TCP buffers.
              • 4. Re: Problem detecting network interruptions
                831532
                Thanks a lot for your reply. Now I'm somewhat clear. can you explane bit more on
                tschodt wrote:
                (*) assuming the TCP stack does not detect and react to media disconnect.
                what are the situations TCP stack detects and cant detect the media disconnect?
                • 5. Re: Problem detecting network interruptions
                  tschodt
                  user13752858 wrote:
                  what are the situations TCP stack detects and cant detect the media disconnect?
                  Media disconnect detection is typically something done in the Network Interface Card driver.

                  If you have two or more routers / switches / hubs between the two boxes
                  and you disconnect the network somewhere not directly connected to your NIC it will not be able to detect it.
                  • 6. Re: Problem detecting network inturruptions
                    802316
                    TCP will reconnect/resend/workaround most problems which can be fixed programmatic-ally. If you are seeing an error, it will be a serious one which there is not much you can do about other than to retry and perhaps notify a human.

                    You get different return values/exception however there is not much you can do about it except notify a human to fix it.
                    All the program can do is to decided whether and how to try again.

                    E.g. say the network is disconnected somewhere, there is no Java command which will reconnect or fix that wire.