[Twisted-Python] protocol connectionLost clientConnectionLost

Kevin McIntyre kmcintyre at greenchargenet.com
Thu Jun 7 22:23:06 EDT 2012

Below is my sample code.  I'm hoping to unplug my internet cable and
get a connectionLost.  But this doesn't happen.  Is there anyway to
detect this?


from twisted.internet.protocol import Protocol, ReconnectingClientFactory
from twisted.internet import reactor

class Echo(Protocol):

    def connectionMade(self):
        print "cool and the gang"

    def connectionLost(self, reason):
        print "ut-oh %s" % reason

    def dataReceived(self, data):

class EchoClientFactory(ReconnectingClientFactory):

    def startedConnecting(self, connector):
        print 'Started to connect.'

    def buildProtocol(self, addr):
        print 'Connected.'
        print 'Resetting reconnection delay'
        return Echo()

    def clientConnectionLost(self, connector, reason):
        print 'Lost connection.  Reason:', reason
        ReconnectingClientFactory.clientConnectionLost(self, connector, reason)

    def clientConnectionFailed(self, connector, reason):
        print 'Connection failed. Reason:', reason
        ReconnectingClientFactory.clientConnectionFailed(self, connector,
if ( __name__ == "__main__" ):
    reactor.connectTCP("", 80, EchoClientFactory() )
#connect to google on port 80


Kevin McIntyre | Software Engineer | Green Charge Networks

Cell 718-249-5058 | kmcintyre at greenchargenet.com | www.greenchargenet.com

More information about the Twisted-Python mailing list