Tornado How To Use Websockets With Wsgi
I am trying to make a game server with python, using tornado. The problem is that WebSockets don't seem to work with wsgi. wsgi_app = tornado.wsgi.WSGIAdapter(app) server = wsgiref
Solution 1:
HTTPServer
needs a tornado.web.Application
, which is not the same as a WSGI application (which you could use with WSGIContainer
).
It is recommended that if you need both WSGI and websockets that you run them in two separate processes with an IPC mechanism of your choice between them (and use a real WSGI server instead of Tornado's WSGIContainer
). If you need to do them in the same process, you can use a FallbackHandler
.
wsgi_container = tornado.wsgi.WSGIContainer(my_wsgi_app)
application = tornado.web.Application([
(r"/ws", MyWebSocketHandler),
(r".*", FallbackHandler, dict(fallback=wsgi_container),
])
Post a Comment for "Tornado How To Use Websockets With Wsgi"