Django-tornado-websockets’s documentation¶
Django-tornado-websockets is a useful solution to provide an easy way to use Tornado WebSockets with a Django application.
Important
Django-tornado-websockets is actually in alpha version!
Architecture¶
To use django-tornado-websockets’s WebSockets, you should use Tornado as a WSGI server where you will define
handlers to handle an incoming request. Since we already have a WSGI server, it’s probably useless to try running
Gunicorn or uWSGI as WSGI server.
You can try to wrap Tornado WSGI server into Gunicorn/uWSGI WSGI server but... It’s a bit retarded I think
(・_・ヾ
...
Let’s explain this diagram:
- The client make a request to our web server with his web browser,
- Our web server (nginx, Apache, ...) pass this WSGI or WebSocket request to Tornado [1],
- If it is a WebSocket request, we pass it to
tornado.websocket
, otherwise it’s Django that will handle this request, - We wait for a WebSocket response or a Django response,
- and 6. Then we return this response to the client.
[1] | I forgot it on the diagram, but nginx or Apache has the job to deliver static files, it’s not Tornado’s work |