SockJS python server implementation on top of Tornado framework
Project description
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:
- Depending on transport, actual client connection might or might not be there. So, there is no _self.request_ and
other tornado.web.RequestHandler properties.
Changed open callback name to on_open to be more consistent with other callbacks.
- 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.
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)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file saet_sockjs_tornado-2.0.1.tar.gz.
File metadata
- Download URL: saet_sockjs_tornado-2.0.1.tar.gz
- Upload date:
- Size: 21.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e8b9a47adf71671346fd6f7891aeeae361b9ed5c5dab399f0044e4118ec44888
|
|
| MD5 |
19c3b15a5585168b1da8a907e3c45bc2
|
|
| BLAKE2b-256 |
52b86ea0edc9976f930a105673d2a85dd1d5502085feb2126253d5c0491b4c67
|
File details
Details for the file saet_sockjs_tornado-2.0.1-py3-none-any.whl.
File metadata
- Download URL: saet_sockjs_tornado-2.0.1-py3-none-any.whl
- Upload date:
- Size: 31.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3ac2504969c108ab1f254914f69c52d730e36f89b875d9a7521c9ce05cf5dc39
|
|
| MD5 |
20248800bedaa925783a91bceb43464b
|
|
| BLAKE2b-256 |
2757c99301c259d2cc818010afaf34e8c29b8b582a76372d7883fbfdcbb0cdcf
|