All Projects → svartalf → tornado-zmq-sockjs-example

svartalf / tornado-zmq-sockjs-example

Licence: other
Example of a application, which uses Tornado web-server for backend side, SockJS for client communications and ØMQ for inner communications.

Programming Languages

python
139335 projects - #7 most used programming language

tornado-zmq-sockjs-example

Example of a application, which uses Tornado web-server for backend side, SockJS for client communications and ØMQ for inner communications.

Installation

  1. Clone this repository

    git clone git://github.com/svartalf/tornado-zmq-sockjs-example.git

  2. Install required libraries

    pip install -r requirements.txt

  3. Run server with a command

    python main.py

  4. Open your browser:

    http://localhost:8080

Pitfalls

Do not save instances of the ZMQ sockets in the connection, this will cause memory leaks! Save instances of the ZMQStream only.

Wrong way:

class SocketConnection(sockjs.tornado.SockJSConnection):

    def __init__(self, *args, **kwargs):
        context = zmq.Context()
        self.publisher = context.socket(zmq.PUB)
        self.publisher.bind(IPC_SOCKET)
        self.publish_stream = ZMQStream(publisher)

Good way:

class SocketConnection(sockjs.tornado.SockJSConnection):

    def __init__(self, *args, **kwargs):
        context = zmq.Context()
        publisher = context.socket(zmq.PUB)  # Notice `self' lack
        publisher.bind(IPC_SOCKET)
        self.publish_stream = ZMQStream(publisher)

Links

See official ZMQ documentation for using Tornado with PyZMQ: http://zeromq.github.com/pyzmq/eventloop.html

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].