GitXplorerGitXplorer
m

sockjs-tornado

public
848 stars
161 forks
37 issues

Commits

List of commits on branch master.
Unverified
ab0f2d5ccf952b481a39318d690dc8d264ad9c50

Fixed #116 XSS issue with the HTML transport

committed 6 years ago
Unverified
81af30f4c1175d99284fb7bcaae1957b83b227d5

New release

mmrjoes committed 6 years ago
Verified
dcd625769bd960349addc4d8a621da6cc93cf39b

Merge pull request #114 from mathben/fix_tornado_5.0_#113

mmrjoes committed 6 years ago
Unverified
212ba2750338c01746f88021dcbd0c0d96267b30

[#113] Fix tornado 5.0 compatibility

mmathben committed 7 years ago
Unverified
85869af90b69e3d9266fd326b762796745b906a0

Merge pull request #104 from mrkschan/patch-1

mmrjoes committed 8 years ago
Unverified
940b7fe6895e36060f1a2d38593544205ba5af63

Merge pull request #106 from cwacekINV/master

mmrjoes committed 8 years ago

README

The README file for this repository.

SockJS-tornado server

SockJS-tornado is a Python server side counterpart of SockJS-client browser library <https://github.com/sockjs/sockjs-client>_ running on top of Tornado <http://tornadoweb.org>_ 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 <https://github.com/MrJoes/sockjs-tornado/tree/master/examples>_ for a complete version).

Subscribe to SockJS mailing list <https://groups.google.com/forum/#!forum/sockjs>_ 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 <https://raw.github.com/sockjs/sockjs-node/master/examples/haproxy.cfg>_.

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)