title: Python Twisted DatagramProtocol UDP Client Reconnect
body: <p>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.</p>
  
  <p>How can I solve a simple reconnect in Twisted or re-initiate the transport?
  I cannot connect again with udp according to the docs.</p>
  
  <p>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.</p>
  
  <p>I suppose running listenUDP again with a new protocol while the core is running won't work.</p>
  
  <pre><code>from twisted.internet.protocol import DatagramProtocol
  from twisted.internet import reactor
  
  
  class UDPClientProtocol(DatagramProtocol):
      def __init__(self, host, port):
         self.host = host
         self.port = port
  
      def startProtocol(self):
         # Called when transport is connected
         self.transport.connect(self.host, self.port)
         self.transport.write('initiate protocol') # pseudo code.
  
      def stopProtocol(self):
         print "I have lost connection and self.transport is gone!"
         # wait some time and try to reconnect somehow?
  
   t = reactor.listenUDP(0, UDPClientProtocol('127.0.0.1', 12345))
   reactor.run()
  </code></pre>