[Twisted-Python] How to create a new service and listen on a new port?

Eric Hsu nkeric at gmail.com
Mon May 23 01:49:21 EDT 2005


Hi all,

This is my first post here, and I'm not a native English speaker, so
please bear with me :)
I'm trying to implement something like this:

 * A UDP server listening on port1 for incoming request
 * A client sends the requset to port1
 * The server confirms the request and creates another (different) UDP
service on a new port (port2)
 * The client then would be able to connect to port2 and do some other things...

By reading this "Writing a New Plug-In for mktap"
 - http://twistedmatrix.com/projects/core/documentation/howto/plugin.html

I've implemented a UDP server and could run it with "twisted -f".
Now the server receives request on port1, and creates a new service at
port2 for client to connect to it.

I implemented this as the following:

class FooServer(DatagramProtocol):
    def datagramReceived(self, data, addr):
        # do something to verify the request and send the client with
a confirm msg
        reactor.listenUDP(port2, AnotherService())
        reactor.run()

class AnotherService(DatagramProtocol):
     # ...

I got this up and run under windows cmd console, however, whenever I
try to stop the server with Ctrl + c or close the cmd console, the
server died in a dead loop which keeps produces tone of error
messages. The only way to quit that console is to "kill" it...

I know there must be something wrong. I would like to know:
  * How could I accomplish this in a more elegant/"formal" way?

I'm very new to twisted and this mailing list, if someone has asked
similar question before, please tell me how to find it. (BTW, how
could I search the mailinglist?)

Thanks in advance! :D




More information about the Twisted-Python mailing list