Conte rages at another Juventus collapse


SUBMITTED BY: Guest

DATE: Feb. 10, 2014, 9:36 p.m.

FORMAT: Python

SIZE: 1.5 kB

HITS: 9480

  1. Given that I have implemented a UDP Client in Twisted with the DatagramProtocol, and using it to communicate to a UDP Server, which at one point goes offline (due to a restart - so it does not change it's IP address), stopProtocol in my protocol is called, however the transport itself is set to None by Twisted.
  2. How can I solve a simple reconnect in Twisted or re-initiate the transport? I cannot connect again with udp according to the docs.
  3. Given that in UDP the sender should be able to send packets even after the server is dead, and given that the protocol has it's own connection handling in the packets, I could reconnect the logical part entirely over the Packet layer, if the transport would not disappear.
  4. I suppose running listenUDP again with a new protocol while the core is running won't work.
  5. from twisted.internet.protocol import DatagramProtocol
  6. from twisted.internet import reactor
  7. class UDPClientProtocol(DatagramProtocol):
  8. def __init__(self, host, port):
  9. self.host = host
  10. self.port = port
  11. def startProtocol(self):
  12. # Called when transport is connected
  13. self.transport.write('initiate protocol') # pseudo code.
  14. def stopProtocol(self):
  15. print "I have lost connection and self.transport is gone!"
  16. # wait some time and try to reconnect somehow?
  17. t = reactor.listenUDP(0, UDPClientProtocol('127.0.0.1', 12345))
  18. reactor.run()

comments powered by Disqus