[muscle] Re: Client killed

  • From: Jeremy Friesner <jaf@xxxxxxxxxxxx>
  • To: muscle@xxxxxxxxxxxxx
  • Date: Fri, 14 Jan 2005 11:29:27 -0800

Hi Julien,

It depends on how the client dies.  If the client dies "nicely" (i.e. the=20
client process exits or crashes, but its operating system and physical=20
network connection to the server continue to operate correctly) then the=20
client PC will send a TCP_DISCONNECT type packet to the server and the serv=
will know to immediately close the connection.  (This is the behaviour you=
should see if you control-C the client... almost instantaneously the server=
should know about it)

If, on the other hand, the client dies "unexpectedly", in such a way that=20
there is no chance for it to send a TCP_DISCONNECT packet to the server (i.=
someone yanked the power cable or network cable out of the client PC, or th=
client's OS crashed, or the client's ISP's router crashed, etc), then the=20
server has no good way of knowing that the client has gone away.

If the server is trying to send data to the client when that occurs, the TC=
packets will start timing out, and eventually (usually after several minute=
the server will give up, assume the client is dead and close the TCP=20
connection.  If the server is not trying to send any data to the client (i.=
the TCP connection is completely idle) then it could be a long time before =
notices the client has gone away... possibly several hours.

If it is important to know quickly when a client has gone away (even in the=
case where the client crashed) then way to do that is by having the client=
and server send "Hi, I'm still alive" type Messages to each other every so=
often -- in my own muscle-based app I implemented a system where these=20
keepalive Messages are sent every few seconds, but you can pick a rate that=
is appropriate based on your application's needs.

Note that just sending some data back and forth is enough to get the TCP=20
protocol to "notice" that a client is not responding (due to too many=20
packet-ack-timeouts) after a few minutes... if you need quicker response ti=
than that, you will need to add logic to your server that force-disconnects=
the client if the server hasn't received any data from the client within th=
timeout period you specify.  Of course, the downside of this is that if you=
make the timeout period too small, you risk disconnecting clients that are=
still alive, just slow for some reason.

As far as Qt signals go, I've only implemented Qt on the client side, but o=
the client side you would see the=20
QMessageTransceiverThread::SessionDisconnected(const String &) signal emitt=
when the TCP connection is broken.

Hope that helps,

On Friday 14 January 2005 09:10, Julien Torr=E8s wrote:
> I have an application with one server and several clients. Is there a=3D20
> way to detect (by the server and by the other clients) if a client is=3D20
> killed ? Is there a QT signal emitted (this does not seems to be) ?

Other related posts: