Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from twisted.internet.protocol import Protocol, ReconnectingClientFactory
- from sys import stdout
- from twisted.internet import reactor, protocol
- HOST = 'localhost'
- PORT = 9000
- class Echo(Protocol):
- def dataReceived(self, data):
- stdout.write(data)
- 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)
- factory = EchoClientFactory()
- reactor.connectTCP(HOST, PORT, factory)
- reactor.run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement