How to listen on multiple udp ports using twisted?

I wrote a server using Python and a Twisted library that communicates via UDP. It all works well.

What I would like to do is expand this server so that it can simultaneously receive messages on several UDP ports (I use different ports to highlight the returned information and less information about the request source). I 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 source on my server, the second line is the second port to listen to.)

When I run this, 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

, UDP, , ( , 18 - ). , ?

+5
1

listenUDP() . , .

+7

All Articles