Advertisement
Guest User

conexion

a guest
Oct 14th, 2011
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.48 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 = "192.168.10.18"
  6. PORT = 997
  7.  
  8. class Echo(Protocol):
  9.  
  10.     def connectionMade(self):
  11.         self.transport.write('\x71')
  12. #-------------------------------------------------------------------------------
  13.        
  14.     def dataReceived(self, data):
  15.         """As soon as any data is received, write it back."""
  16.        
  17.         cadena = repr(data)
  18.     # Trabajo con los datos obtenidos
  19.  
  20. class EchoClientFactory(ReconnectingClientFactory):
  21.    
  22.     protocol = Echo
  23.    
  24.     def startedConnecting(self, connector):
  25.         print 'Started to connect.'
  26.  
  27.     def buildProtocol(self, addr):
  28.         print 'Connected.'
  29.         print 'Resetting reconnection delay'
  30.         self.resetDelay()
  31.         p = self.protocol()
  32.         p.factory = self
  33.         return p
  34.  
  35.     def clientConnectionLost(self, connector, reason):
  36.         print 'Lost connection.  Reason:', reason
  37.         ReconnectingClientFactory.clientConnectionLost(self, connector, reason)
  38.  
  39.     def clientConnectionFailed(self, connector, reason):
  40.         print 'Connection failed. Reason:', reason
  41.         ReconnectingClientFactory.clientConnectionFailed(self, connector, reason)
  42.  
  43.  
  44.  
  45.  
  46. def main():
  47.     factory = EchoClientFactory()
  48.     factory.maxDelay = 30  
  49.     reactor.connectTCP(HOST, PORT, factory)
  50.     reactor.run()
  51.    
  52. if __name__ == '__main__':
  53.     main()
  54.    
  55.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement