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 = "192.168.10.18"
- PORT = 997
- class Echo(Protocol):
- def connectionMade(self):
- self.transport.write('\x71')
- #-------------------------------------------------------------------------------
- def dataReceived(self, data):
- """As soon as any data is received, write it back."""
- cadena = repr(data)
- # Trabajo con los datos obtenidos
- class EchoClientFactory(ReconnectingClientFactory):
- protocol = Echo
- def startedConnecting(self, connector):
- print 'Started to connect.'
- def buildProtocol(self, addr):
- print 'Connected.'
- print 'Resetting reconnection delay'
- self.resetDelay()
- p = self.protocol()
- p.factory = self
- return p
- 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)
- def main():
- factory = EchoClientFactory()
- factory.maxDelay = 30
- reactor.connectTCP(HOST, PORT, factory)
- reactor.run()
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement