Last active
April 20, 2021 15:46
-
-
Save pizzapanther/3a55899e909dbf1327087a69893d344b to your computer and use it in GitHub Desktop.
Tornado + Django WebSocket Combination
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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