Skip to content
Newer
Older
100644 61 lines (38 sloc) 2.24 KB
3b70beb @mrjoes Updated readme.
authored Dec 19, 2011
1 SockJS-tornado server
2 =====================
3
e5d43af @mrjoes Refactored raw/json message encoding optimizations.
authored Mar 5, 2012
4 SockJS-tornado is a Python server side counterpart of `SockJS-client browser library <https://github.com/sockjs/sockjs-client>`_
5 running on top of `Tornado <http://tornadoweb.org>`_ framework.
3b70beb @mrjoes Updated readme.
authored Dec 19, 2011
6
7 Simplified echo SockJS server could look more or less like::
8
9 from tornado import web, ioloop
10 from sockjs.tornado import SockJSRouter, SockJSConnection
11
12 class EchoConnection(SockJSConnection):
13 def on_message(self, msg):
14 self.send(msg)
15
16 if __name__ == '__main__':
17 EchoRouter = SockJSRouter(EchoConnection, '/echo')
18
19 app = web.Application(EchoRouter.urls)
20 app.listen(9999)
21 ioloop.IOLoop.instance().start()
22
e5d43af @mrjoes Refactored raw/json message encoding optimizations.
authored Mar 5, 2012
23 (Take look at `examples <https://github.com/MrJoes/sockjs-tornado/tree/master/examples>`_ for a complete version).
3b70beb @mrjoes Updated readme.
authored Dec 19, 2011
24
e5d43af @mrjoes Refactored raw/json message encoding optimizations.
authored Mar 5, 2012
25 Subscribe to `SockJS mailing list <https://groups.google.com/forum/#!forum/sockjs>`_ for discussions and support.
3b70beb @mrjoes Updated readme.
authored Dec 19, 2011
26
27 SockJS-tornado API
28 ------------------
29
49b7b79 @reclosedev Minor formatting changes in README.rst
reclosedev authored May 4, 2012
30 SockJS provides slightly different API than ``tornado.websocket``. Main differences are:
0778357 @mrjoes Another list fix
authored Dec 19, 2011
31
089ae2b @mrjoes Typo.
authored Dec 19, 2011
32 1. Depending on transport, actual client connection might or might not be there. So, there is no _self.request_ and
49b7b79 @reclosedev Minor formatting changes in README.rst
reclosedev authored May 4, 2012
33 other ``tornado.web.RequestHandler`` properties.
34 2. Changed ``open`` callback name to ``on_open`` to be more consistent with other callbacks.
35 3. Instead of ``write_message``, all messages are sent using ``send`` method. Just in case, ``send`` in ``tornado.web.RequestHandler``
089ae2b @mrjoes Typo.
authored Dec 19, 2011
36 sends raw data over the connection, without encoding it.
49b7b79 @reclosedev Minor formatting changes in README.rst
reclosedev authored May 4, 2012
37 4. There is handy ``broadcast`` function, which accepts list (or iterator) of clients and message to send.
3b70beb @mrjoes Updated readme.
authored Dec 19, 2011
38
39 Settings
40 --------
41
49b7b79 @reclosedev Minor formatting changes in README.rst
reclosedev authored May 4, 2012
42 You can pass various settings to the ``SockJSRouter``, in a dictionary::
3b70beb @mrjoes Updated readme.
authored Dec 19, 2011
43
44 MyRouter = SockJSRouter(MyConnection, '/my', dict(disabled_transports=['websocket']))
45
46 Deployment
47 ----------
48
49 sockjs-tornado properly works behind haproxy and it is recommended deployment approach.
50
e5d43af @mrjoes Refactored raw/json message encoding optimizations.
authored Mar 5, 2012
51 Sample configuration file can be found `here <https://raw.github.com/sockjs/sockjs-node/master/examples/haproxy.cfg>`_.
3b70beb @mrjoes Updated readme.
authored Dec 19, 2011
52
49b7b79 @reclosedev Minor formatting changes in README.rst
reclosedev authored May 4, 2012
53 If your log is full of "WARNING: Connection closed by the client", pass ``no_keep_alive`` as ``True`` to ``HTTPServer`` constructor::
3b70beb @mrjoes Updated readme.
authored Dec 19, 2011
54
55 HTTPServer(app, no_keep_alive=True).listen(port)
56
57 or::
58
59 app.listen(port, no_keep_alive=True)
60
Something went wrong with that request. Please try again.