SockJS python server implementation 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 provides slightly different API than tornado.websocket. Main differences are:
You can pass various settings to the SockJSRouter, in a dictionary:
MyRouter = SockJSRouter(MyConnection, '/my', dict(disabled_transports=['websocket']))
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:
- Tornado 4.x compatibility fix
- 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
- 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
- Added support for older simplejson library versions
- Fixed installation script
- SockJS 0.3 support
- Connection multiplexing sample
- IP validation is now optional
- SockJS 0.2 support and compatibility fixes