I've written a server using Python and the Twisted library that communicates via UDP. This all works well.
What I would like to do is extend that server so that it can accept messages on multiple UDP ports simultaneously (I use the different ports to segregate the information returned, and it's less about the source of the request). I've tried to do the simplest thing first as a test - I wrote code that looks like this:
reactor.listenUDP(port, handler)
reactor.listenUDP(port+1, handler)
(The first line is the one originally in my server; the second line is the 2nd port to listen to.)
When I run that, I get the following:
File "./rspServer.py", line 838, in mainLoop
reactor.listenUDP(self.args.port+1, udpHandler)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/twisted/internet/posixbase.py", line 347, in listenUDP
p.startListening()
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/twisted/internet/udp.py", line 86, in startListening
self._connectToProtocol()
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/twisted/internet/udp.py", line 106, in _connectToProtocol
self.protocol.makeConnection(self)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/twisted/internet/protocol.py", line 665, in makeConnection
assert self.transport == None
AssertionError
I take from this that I can't add a second UDP listener, but that's exactly what I'd like to do (actually, to make a total of 18 listeners - it's a long story). Any thoughts on how to do this?
Each call to listenUDP() needs a unique handler instance. Other than that, your code looks fine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With