Eat at Joe's

What is SockJS?

SockJS is a browser JavaScript library that provides a WebSocket-like object. SockJS gives you a coherent, cross-browser, Javascript API which creates a low latency, full duplex, cross-domain communication channel between the browser and the web server.

Under the hood SockJS tries to use native WebSockets first. If that fails it can use a variety of browser-specific transport protocols and presents them through WebSocket-like abstractions.

SockJS is intended to work for all modern browsers and in environments which don't support WebSocket protcol, for example behind restrictive corporate proxies.

If you worked with socket.io before, you might think that it is another socket.io spin-off. Well, there are some major differences between these two libraries:

sockjs-tornado

sockjs-tornado is SockJS implementation on top of Tornado framework. It is very fast (details will be posted soon), passes sockjs-protocol test and just works.

If you worked with TornadIO, you will find API very similar. This is a simple echo server:

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()

Anyway, hope you'll like it.

blog comments powered by Disqus