pythontwistedtwistdautobahn

Run autobahn application with twistd


I've developed a websocket server on Twisted with autobahn lib. Now I want to run it as a daemon with twistd. In case of simple TCP server I would do something like that:

application = service.Application("someapp")  # create the Application
someService = internet.TCPServer(port, someFactory) # create the service
someService.setServiceParent(application)

In that example I'm useing TCPServer class instead of reactor.listenTCP function.

In autobahn api reference I found only listenWS function (like listenTCP for TCP server) and nothing about WSServer class.

So my question is how can I get my app work with twistd? Maybe I should implement my own service WSServer class that extends twisted Service class?


Solution

  • Yep. Create your own service. Call listenWS in its startService method. Call the shutdown method in the stopService method.