Advertisement
joshtrier

Untitled

Jun 20th, 2011
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.02 KB | None | 0 0
  1. from twisted.internet.protocol import Protocol, ReconnectingClientFactory
  2. from sys import stdout
  3. from twisted.internet import reactor, protocol
  4.  
  5. HOST = 'localhost'
  6. PORT = 9000
  7.  
  8. class Echo(Protocol):
  9.     def dataReceived(self, data):
  10.         stdout.write(data)
  11.  
  12. class EchoClientFactory(ReconnectingClientFactory):
  13.     def startedConnecting(self, connector):
  14.         print 'Started to connect.'
  15.  
  16.     def buildProtocol(self, addr):
  17.         print 'Connected.'
  18.         print 'Resetting reconnection delay'
  19.         self.resetDelay()
  20.         return Echo()
  21.  
  22.     def clientConnectionLost(self, connector, reason):
  23.         print 'Lost connection.  Reason:', reason
  24.         ReconnectingClientFactory.clientConnectionLost(self, connector, reason)
  25.  
  26.     def clientConnectionFailed(self, connector, reason):
  27.         print 'Connection failed. Reason:', reason
  28.         ReconnectingClientFactory.clientConnectionFailed(self, connector, reason)
  29.  
  30.  
  31. factory = EchoClientFactory()
  32. reactor.connectTCP(HOST, PORT, factory)
  33. reactor.run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement