Twisted UDP Server - a daemon?

I have the following UDP server using Twisted:

# init the thread capability
threadable.init(1)

# set the thread pool size
reactor.suggestThreadPoolSize(32)

class BaseThreadedUDPServer(DatagramProtocol):
    def datagramReceived(self, datagram, (host, port)):
        #do some stuff here...

def main():
    reactor.listenUDP(PORT, BaseThreadedUDPServer())
    reactor.run()

if __name__ == '__main__':
    main()

I would like to be able to dismantle this, so from what I read, I have to do something with a .tac file that I can start with "twistd -y my_udp_server_file.tac" - the problem is that I cannot find any documentation on how to do this with this setup. All I can find are examples of how to dismantle simple TCP echo servers (with a .tac file, that is). I need a multithreaded UDP server, such as the one I have.

Any direction is welcome.

+3
source share
2 answers

Try the following:

import twisted.application
application = twisted.application.service.Application("Scotty UDP server")
twisted.application.internet.UDPServer(PORT, BaseThreadedUDPServer()).setServiceParent(application)
+3
source

twistd , UDP TCP. UDP- , TCP-. - TCP .tac UDP-.

+3

Source: https://habr.com/ru/post/1769502/


All Articles