Detecting unexpectedly closed sockets

Dar Scott dsc at
Sat Oct 16 13:46:37 EDT 2004

On Oct 15, 2004, at 4:13 PM, Tomas Franzén wrote:

> I work on a project where a bunch of clients connect to the same 
> server. The server needs to keep track of which users are connected.
> The server adds the address of the client to a list when connected, 
> and removes it when disconnected. I can easily track connections using 
> the callback message of the accept command, and disconnections using 
> the socketClosed message. However, how do I detect when a client 
> unexpectedly loses its connection?

Here are some methods:

The traditional one is to time-out based on the time since the most 
recent message from the client.

You can also have the client (and even the server) send an "alive" 
message every once in a while and shut down the link if one is very 
late.  This is the same as suggested by Xavier.

You can make your link a higher level than a TCP connection and have 
your TCP connection be an atomic transaction.  However, this only 
shifts the problem to the higher level.  But, if you have no higher 
level, the dangling connection goes away, but the server is not able to 
keep up with clients, except maybe by a timer.  The www is like this.

Typically, a client can reconnect if the connection is lost.  Consider 
whether your situation allows this:  If a client connects, then it is 
OK to close all other connections for that client.  This can apply to 
the above methods.

     Dar Scott Consulting
     Programming Services

More information about the Use-livecode mailing list