SocketTornad.IO: Server-side Websockets for Tornado and

Socket.IO, the popular Websockets library gets some Python love from Brendan McAdams.

SocketTornad.IO adds Websockets support to your Tornado app, handling all the protocol details on the server to wire up to the usual Socket.IO client libraries in the browser.

In the simplest case, your Tornado app need only subclass tornad_io.socket_io.SocketIOHandler and handle on_message, and optionally on_open and on_close events.

class EchoHandler(SocketIOHandler):
    def on_open(self, *args, **kwargs):"Socket.IO Client connected with protocol '%s' {session id: '%s'}" % (self.protocol,"Extra Data for Open: '%s'" % (kwargs.get('extra', None)))

    def on_message(self, message):"[echo] %s" % message)
        self.send("[echo] %s" % message)

    def on_close(self):"Closing Socket.IO Client for protocol '%s'" % (self.protocol))

The upside of using Socket.IO on the client is broad fallback support for browsers that do not support Websockets including Adobe Flash Socket, AJAX long polling, AJAX multipart streaming, Forever Iframe and, JSONP Polling.

Be sure to check the SocketTornad.IO README for advanced usage.

[Source on GitHub] [Socket.IO]

News Films

Our little film studio focuses on telling developer-centric stories that need to be seen.

GopherCon 2016 Conference Recap

0:00 / 0:00