How to monitor remote service: promptly detect if it is up and running or down/unreachable

  c++, linux, tcp, windows

This is primarily TCP related question, but I would like try out my solution using both system calls and high levels libs such as boost.

How to monitor a service on a remote endpoint? Check if it is running or down/unreachable and promptly detect when service changes its state. Service doesn’t support any health check methods. In fact, I don’t need to know what exactly that service does. All I need to know whether service up or down and promptly detect when it goes down or comes back online.

The first thing that came to my mind is to try to establish tcp connection periodically and consider service as down/unreachable depending on connection success. Is there more elegant/efficient solution?

Source: Windows Questions