Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Tornado + Django WebSocket Combination
#!/usr/bin/env python
import tornado.httpserver
import tornado.ioloop
import tornado.log
import tornado.web
import tornado.wsgi
import tornado.websocket
class MyWebSocket(tornado.websocket.WebSocketHandler):
# Put your WebSocket code here
pass
def main():
tornado.log.enable_pretty_logging()
from myapp.wsgi import application
container = tornado.wsgi.WSGIContainer(application)
tornado_app = tornado.web.Application([
('/realtime-stuff$', MyWebSocket),
('.*', tornado.web.FallbackHandler, dict(fallback=container)),
], autoreload=False)
server = tornado.httpserver.HTTPServer(tornado_app)
server.listen(8000)
tornado.ioloop.IOLoop.instance().start()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.