Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to deal with network drops and Indy IdTCPServer

Tags:

tcp

delphi

indy10

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".

like image 353
M Schenkel Avatar asked Jul 27 '10 12:07

M Schenkel


1 Answers

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.)

like image 120
mjn Avatar answered Oct 15 '22 12:10

mjn