Django-tornado-websockets’s documentation — Django-tornado-websockets 0.0.7 documentation

# 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

Example of an architecture using Tornado as WSGI server, Django and django-tornado-websockets

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:

1. The client make a request to our web server with his web browser,
2. Our web server (nginx, Apache, ...) pass this WSGI or WebSocket request to Tornado [1],
3. If it is a WebSocket request, we pass it to `tornado.websocket`, otherwise it’s Django that will handle this request,
4. We wait for a WebSocket response or a Django response,
5. 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

## Documentation

- 1. Installation
  - 1.1. Automatic installation
  - 1.2. Manual installation
- 2. Django integration and configuration
  - 2.1. Integration
  - 2.2. Configuration
    - 2.2.1. Basic configuration
    - 2.2.2. Django support
    - 2.2.3. Static files support
    - 2.2.4. Additional settings
- 3. Usage
  - 3.1. Run Tornado server
  - 3.2. Using WebSockets (server side)
    - 3.2.1. Create a WebSocket
    - 3.2.2. Listening to an event
    - 3.2.3. Emit an event
  - 3.3. Using WebSockets (client side)
- 4. API
  - 4.1. WebSocket
  - 4.2. WebSocketHandler
  - 4.3. TornadoWrapper
  - 4.4. Exceptions