There are many reasons that a TCP connection can be lost, not the least of which is the NAT router that it might sit behind. In my ongoing efforts to develop a private mail system, I needed to know if a client was still connected to the server. There was also a need to provide for a Client to connect to the server when it becomes available. So I developed a Heart Beat system.
This is a dual purpose system. In the examples I have provided, the Client includes a timer that is set to activate every 5 time slots. Normally the time slot would be 60 seconds (1 minute), but for testing I reduced it to 10 seconds. If the client is not currently connected to the server, it will attempt to connect. If it is already connected to the server, then it sends a Heart Beat packet to signal to the server that it is still alive and connected.
The server in essence ignores the packet, except that it increments a counter. The server also contains a timer, but this one activates every 10 time slots. If the Client has not sent any traffic in the last 10 time slots, the counter is zero and it is disconnected.
J.A. Coutts
This is a dual purpose system. In the examples I have provided, the Client includes a timer that is set to activate every 5 time slots. Normally the time slot would be 60 seconds (1 minute), but for testing I reduced it to 10 seconds. If the client is not currently connected to the server, it will attempt to connect. If it is already connected to the server, then it sends a Heart Beat packet to signal to the server that it is still alive and connected.
The server in essence ignores the packet, except that it increments a counter. The server also contains a timer, but this one activates every 10 time slots. If the Client has not sent any traffic in the last 10 time slots, the counter is zero and it is disconnected.
J.A. Coutts