Skip to main content

SockJS-tornado server

SockJS-tornado is a Python server side counterpart of SockJS-client browser library running on top of Tornado framework.

Simplified echo SockJS server could look more or less like:

from tornado import web, ioloop
from sockjs.tornado import SockJSRouter, SockJSConnection

class EchoConnection(SockJSConnection):
    def on_message(self, msg):
        self.send(msg)

if __name__ == '__main__':
    EchoRouter = SockJSRouter(EchoConnection, '/echo')

    app = web.Application(EchoRouter.urls)
    app.listen(9999)
    ioloop.IOLoop.instance().start()

(Take look at examples for a complete version).

Subscribe to SockJS mailing list for discussions and support.

SockJS-tornado API

SockJS provides slightly different API than tornado.websocket. Main differences are:

  1. Depending on transport, actual client connection might or might not be there. So, there is no _self.request_ and other tornado.web.RequestHandler properties.

  2. Changed open callback name to on_open to be more consistent with other callbacks.

  3. Instead of write_message, all messages are sent using send method. Just in case, send in tornado.web.RequestHandler sends raw data over the connection, without encoding it.

  4. There is handy broadcast function, which accepts list (or iterator) of clients and message to send.

Settings

You can pass various settings to the SockJSRouter, in a dictionary:

MyRouter = SockJSRouter(MyConnection, '/my', dict(disabled_transports=['websocket']))

Deployment

sockjs-tornado properly works behind haproxy and it is recommended deployment approach.

Sample configuration file can be found here.

If your log is full of “WARNING: Connection closed by the client”, pass no_keep_alive as True to HTTPServer constructor:

HTTPServer(app, no_keep_alive=True).listen(port)

or:

app.listen(port, no_keep_alive=True)

Changelog

1.0.1

  • Tornado 4.x compatibility fix

1.0.0

  • Major version bump. sockjs-tornado can be considered mature

  • Python 3 support

  • Tornado 3.0 support on both Python 2 and Python 3

  • Bug fixes

0.0.5

  • iOS 6 support

  • SockJS 0.3.3 client support

  • Some headers and request URI path is now passed to on_open handler

  • Added binary transport support for raw websocket transport

  • Minor multiplex sample fixes

0.0.4

  • Added support for older simplejson library versions

  • Fixed installation script

0.0.3

  • SockJS 0.3 support

  • Connection multiplexing sample

  • IP validation is now optional

0.0.2

  • SockJS 0.2 support and compatibility fixes

0.0.1

Initial release.

Metadata

Release files for sockjs-tornado-meiqia 2016.12.30

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sockjs-tornado-meiqia 2016.12.30
File Size Uploaded
sockjs-tornado-meiqia-2016.12.30.tar.gz 21.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for sockjs-tornado-meiqia 2016.12.30
File Interpreter ABI Platform
sockjs_tornado_meiqia-2016.12.30-py2-none-any.whl Python 2 none any Details

Total release size: 55.9 kB

Release files / sockjs-tornado-meiqia-2016.12.30.tar.gz

Download URL sockjs-tornado-meiqia-2016.12.30.tar.gz
Size 21.7 kB
Tags Source
SHA-256 checksum
How to use checksums
1a682107da44de4d3dc50a0866a519104a60b37cd6fbec2bd8f7ab07b0de7f47
BLAKE2b-256 checksum
How to use checksums
ae40eabaf8994e4b4853eaff96c0201c86d7537575204ce4a33d83876d6d8116
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / sockjs_tornado_meiqia-2016.12.30-py2-none-any.whl

Download URL sockjs_tornado_meiqia-2016.12.30-py2-none-any.whl
Size 34.3 kB
Tags Python 2
SHA-256 checksum
How to use checksums
d324c5711a16e1286848fd64210d371fa7c34191a2e582ab4cd67512764a4bec
BLAKE2b-256 checksum
How to use checksums
4e89c3ad2715403c1b8f9439dba18048d2cafdb304de2bbcb54b8c0c4f9e56d0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

2016.12.30 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page