[Twisted-Python] How to detect dead client connections in twisted

Alvin Delagon adelagon at gmail.com
Sun Jun 1 22:41:33 EDT 2008

I've been using xmlstream for quite sometime now and I noticed one such
problem where my server doesn't detect clients that went to hardware
shutdown without closing the socket. I also reproduced it using a simple
twisted TCP server:

from twisted.internet import protocol
from twisted.internet import reactor

class EchoProtocol(protocol.Protocol):
    def __init__(self):

    def connectionMade(self):
        print "Client Connected Detected!"

    def connectionLost(self, reason):
        print "Client Connection Lost!"

    def dataReceived(self, data):

factory = protocol.Factory()
factory.protocol = EchoProtocol
reactor.listenTCP(8000, factory)

Using a different machine, telnet to the echo server and then shut down the
computer (without exiting telnet). It seems that the connectionLost function
doesn't get called. I even had an XMPP account appeared online on our XMPP
server for almost three days even though I shut down the PC hosting my
client. Should we implement a Hearbeat functionality? Thank you in advance!

Alvin Delagon

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://twistedmatrix.com/pipermail/twisted-python/attachments/20080602/494bf05c/attachment.htm 

More information about the Twisted-Python mailing list