how can i make the server listen for TCP and UDP?

python, tcp, twisted, udp

Solution

This is just a rephrasing of MarkR's answer, which is right, but I thought it might be a bit clearer to spell out exactly how this works:

Instead of what you propose, your program should look like this:

reactor.listenTCP(PORT, factory)
reactor.listenUDP(PORT, BaseThreadedUDPServer())
reactor.run()

It's helpful to think of `reactor.run()`as meaning "run the entire program, and then exit, I'm done". You should only run the reactor once per program. However, before you run it, and while it's running, you may call as many methods as you like to listen for new protocols or call new timed events.

Problem

i'm using python twisted and i have two separate servers working, one that recieves TCP, one that receives UDP and they each use ``` reactor.listenTCP(PORT, factory) reactor.run() ``` and ``` reactor.listenUDP(PORT, BaseThreadedUDPServer()) reactor.run() ``` They both work but now I want to combine them into one server that recieves both TCP and UDP but they both use the variable `reactor`. Isn't the `reactor` twisted's, not my own. If it were my own, I could just change the name for each. Thank you!

Original source