[Twisted-Python] Getting local UDP address/port

I am implementing a UDP protocol where a request is sent to a server through a connected UDP transport. I listen for the answer using reactor.listenUDP(0, myDatagramProtocol). The local port is not in itself significant (hence the 0), but the protocol require that I get the local IP address and port of the socket used to send the request (so that I can properly process the answser). How can I get this information ? datagramReceived only provides me with the source address and port of the answer (as can be expected). Regards, Olivier.

On 03:02 pm, olivier.parisy@free.fr wrote:
I am implementing a UDP protocol where a request is sent to a server through a connected UDP transport.
I listen for the answer using reactor.listenUDP(0, myDatagramProtocol).
The local port is not in itself significant (hence the 0), but the protocol require that I get the local IP address and port of the socket used to send the request (so that I can properly process the answser).
How can I get this information ? datagramReceived only provides me with the source address and port of the answer (as can be expected).
The protocol's transport will give you this information via the getHost method: http://twistedmatrix.com/documents/current/api/twisted.internet.interfaces.I... However, unless you're using connected UDP, the platform may not bother to give you a realistic local address (and perhaps sometimes even for connected UDP it won't). And then there's always NAT. Jean-Paul

exarkun@twistedmatrix.com a écrit :
The protocol's transport will give you this information via the getHost method:
http://twistedmatrix.com/documents/current/api/twisted.internet.interfaces.I...
I got confused by the method name and did not think it would provide me with the local port. This is exactly what I needed, thanks!
However, unless you're using connected UDP, the platform may not bother to give you a realistic local address (and perhaps sometimes even for connected UDP it won't). And then there's always NAT.
Yes, I am aware of those issues. This is kind of the point of my test actually. Thanks, Olivier.
participants (2)
-
exarkun@twistedmatrix.com
-
Olivier Parisy