I want to write a kind of "diagnostic function" which is able to detect when a TCP/IP based network is interrupted.

I would like to connect two endpoints and detect when an established connection between them two is dropped. The network connection can be wired or wireless. The check should be independent of operating system or network driver function: I don't want to read "packet retry counters" or similar because I think this won't work out. The diagnosis should run for hours or even days so when the connection gets dropped I should be able to detect this, increase a count and then reestablish the connection for further measurements.

My first idea was to use Netty or Mina but I failed because they reestablish connections silently (which normally is a good thing) I need a pointer in the right direction.

1 Answer 1


There are two methods that come to mind:

  1. Have one system ping another. If the ICMP packet cannot reach the other system, there is some disruption between them.

  2. Set up a simple ACK function using TCP or UDP. This is more appropriate than ping if you need to communicate metadata. How this works is similar to ping, one system sends a request to another system which then returns a response. If no response comes back in a set amount of time, the other system is not reachable. TCP has its own built-in ACK function and is more fault-tolerant, while UDP will drop packets. Which one you use depends on how tolerant you want to be of minor network hiccups as opposed to "someone unplugged the network cable."

  • 1
    The effectiveness of ping is dependent upon the network. If you are not in control of the network I wouldn't use ping. All it takes is the network engineer to decide to turn off ICMP Echo request / replies and you are sunk. If google ever does that the world economy may crash based on the code that I have seen that pings google to determine if the 'network' is OK.
    – dbasnett
    Commented Apr 4, 2016 at 11:48
  • @dbasnett Although the networks I have to consider are very likely providing support for PING: do you have a suggestion ? If this would be a serial line I would monitor RTS / CTS so I am looking for something similar .
    – Marged
    Commented Apr 4, 2016 at 13:52
  • Answer two above seems reasonable, but it really depends on what the specifics are. You should post your own question. Comments aren't to ask other questions.
    – dbasnett
    Commented Apr 4, 2016 at 23:01
  • @dbasnett I thought it was a concretization of my question ;-)
    – Marged
    Commented Apr 5, 2016 at 5:30
  • Sorry, wasn't paying attention, it is your question. Still, did you try snowman's second method?
    – dbasnett
    Commented Apr 5, 2016 at 11:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.