Remove Connection TCP SERVER

Hi
I made a server using TCP panda3d. I want to know when to disconnect a client from the server, how this is done?. I’m thinking of doing the following:

  1. Create a task on the client that sends a data every second or every two seconds, these data report the server that the client is active.

  2. Create a task in the sever to update the “time out” of all the connections, if “time out” of connection is more than 6 seconds, then the connection is lost and then the client is disconnected from the server …

would be something like this on the server side:

#dictionary whose key customer and value "time out" accumulated
timeOut = {}

# for each client that is active ...
for client in activeConnections:
     #if has accumulated more than 6 seconds without receiving report from the customer 
     if timeOut[client] >= 6:
        #remove connection of client from the server
        removeConnection (client)
        #inform other users that the client is disconnected...

This is fine? There a better and efficient way to do this? 6 seconds is a good measure for the “time out”?

Thank you!

The strategy you describe is called using a “heart beat” and yes it is a valid technique; when the heart beat fails for a given amount of time the connection is closed. Just be sure to use the smallest sized chunk of data for your heart beat that you can.

Thanks for your answer, it has served me fairly. The only question I have is … 6 seconds is a good measure for the “time out”?
Thanks!

How long you wait before disconnecting would be based on the needs for your game, though 6 seconds might be a bit short for a typical game. Another strategy, rather than just disconnecting the client straight away, is to put the client into a “suspended” state; you then begin polling the client at regular time intervals to see if you can re-establish the connection. Each call to the client happens after twice as much time as the previous call, so you call the client and then wait 10 seconds and call the client again and if there is still no response you wait 20 seconds and then try again, and then 40 seconds, and then 80 seconds for however long you want. Only after you’re totally sure the client is gone do you officially disconnect them. But, again, it depends entirely on your needs for your game.

Thank you very much for your help, has been very useful.