[Twisted-Python] protocol connectionLost clientConnectionLost

Kevin McIntyre kmcintyre at greenchargenet.com
Thu Jun 7 20:23:06 MDT 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):
        pass

class EchoClientFactory(ReconnectingClientFactory):

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

    def buildProtocol(self, addr):
        print 'Connected.'
        print 'Resetting reconnection delay'
        self.resetDelay()
        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,
                                                         reason)
if ( __name__ == "__main__" ):
    reactor.connectTCP("74.125.224.242", 80, EchoClientFactory() )
#connect to google on port 80
    reactor.run()

-- 

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