I have created a Client/Server application with the IdTCPServer component. The clients connect and maintain a persistent connection through the life of the application. If the network connection is dropped (which happens quite frequently because clients connect with wireless aircards) the client will automatically re-connect. This all works fine.
My problem is dealing with the sockets on the server corresponding to the lost connection. They don't detect the network drop and disconnect themselves. After reading several related articles, I have learned there is no way for the server to know if a connection was dropped. It must wait for some event to find this out.
So my question is, should I build some mechanism into my server to periodically "handle" the sockets with dropped connections? And if so, how? I thought one way would be do cycle through all connections and attempt to send them data. I find this will trigger that needed "event".
Some kind of heartbeat or ping signal, sent from client to server in regular intervals, could be used to keep the server-side session alive. If the signal stops, and a timeout interval passes, the server can assume that the client has lost the connection.
(If the server simply uses the socket connection to send data back to the client, the server can not know if the client received it. The data might be somewhere in the middle.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With