[Twisted-Python] Dynamic listening to UDP ports?

Jp Calderone exarkun at divmod.com
Tue Apr 26 11:26:38 MDT 2005


On Tue, 26 Apr 2005 18:27:05 +0200, Torbjörn Einarsson <torbjorn at einarssons.se> wrote:
>Hi,
>
>
>
>I’m trying to make a server that listens to one TCP socket for commands and
>then starts listening to more or less UDP sockets for data depending on the
>commands. The UDP data shall then be forwarded to one or more outgoing UDP
>ports.
>
>For example, here are some commands with explanations:
>
>addChannel 10000                             should make the server
>listening to UDP port 10000
>
>addChannel 10002                             should make the server
>listening to UDP port 10002
>
>addConnection 10000 10.0.0.2:5000    start forwarding the packet from UDP
>port 10000 to port 5000 on another machine
>
>addConnection 10000 10.0.0.3:5002    start forwarding the packet from UDP
>port 10000 to port 5002 on yet another machine
>
>delConnection  10000 10.0.0.2:5000    stop forwarding packets to the first
>guy
>
>delConnection  10000 10.0.0.3:5002    stop forwarding packets to the second
>guy
>
>delChannel      10000                         stop listening to port 10000
>
>
>
>I’ve been making some rather advanced servers in twisted, but with fixed
>ports. How can I deal with this type of dynamic port bindings?
>
>For adding a port to listen to: reactor.listenUDP(10000,prot) is working,
>but how do I stop listening to a port an unbind it? I’ve found something
>called unlistenUDP but it seems to be deprecated?

  listenUDP returns a udp.Port.  Call stopListening() on that Port and it will shut down.

>
>Alternatively, I could start up a service , like
>
>u = internet.services.UDPServer(10000,UdpProtocol())
>
>but how do I stop this particular service without stopping all others?
>

  Just call stopService() on it.  How you arrange to know which services should have this called on them and how you track your services depends on your specific application.

  Jp




More information about the Twisted-Python mailing list