Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mrjoes/sockjs-tornado
WebSocket emulation - Python server
https://github.com/mrjoes/sockjs-tornado
Last synced: 13 days ago
JSON representation
WebSocket emulation - Python server
- Host: GitHub
- URL: https://github.com/mrjoes/sockjs-tornado
- Owner: mrjoes
- License: mit
- Created: 2011-12-06T20:41:39.000Z (almost 13 years ago)
- Default Branch: master
- Last Pushed: 2023-08-04T15:50:54.000Z (over 1 year ago)
- Last Synced: 2024-09-24T08:36:02.930Z (about 2 months ago)
- Language: Python
- Homepage:
- Size: 230 KB
- Stars: 850
- Watchers: 49
- Forks: 163
- Open Issues: 37
-
Metadata Files:
- Readme: README.rst
- License: LICENSE
Awesome Lists containing this project
README
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)