[Twisted-Python] Transfering a transport between DatagramProtocols

Glyph Lefkowitz glyph at twistedmatrix.com
Tue Nov 24 16:13:52 MST 2009


On Nov 24, 2009, at 4:26 PM, Olivier Parisy wrote:

> Is this the "twisted" way to analyse this? Or should I use some kind of 
> "proxy" DatagramProtocol which would relay datagramReceived calls to the 
> proper DatagramProtocol, depending on the current protocol state 
> (handshaking or data exchange)?

Currently, the right way to do this is to do as you suggest, and have two DatagramProtocol instances, and a third which switches between them.

Now, it just so happens that there is an accidental feature of udp.Port, whereby you can do self.udpPort.protocol = someOtherProtocol, and it will work.  However, this feature is not supported and may break in a future version of Twisted.

In the future, however, it would be reasonable and useful to have an explicit "switch protocol" method, which would tear down one protocol/transport relationship and set up another.  If you would like to open a ticket and contribute a patch to do this, that would be great :).






More information about the Twisted-Python mailing list