Wynn Netherland changelog.com/posts

SocketTornad.IO: Server-side Websockets for Tornado and Socket.io

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):
        logging.info("Socket.IO Client connected with protocol '%s' {session id: '%s'}" % (self.protocol, self.session.id))
        logging.info("Extra Data for Open: '%s'" % (kwargs.get('extra', None)))

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

    def on_close(self):
        logging.info("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]


Sign in or Join to comment or subscribe

0:00 / 0:00