Hacking on Empty

eat something, you'll feel better

Socket.IO + TornadIO2 == happy hacking

leave a comment »

I’m building a little appliance with a web interface so I needed to do some comet/websockets whatever. I wanted something that worked straight away with minimal pain. Surprisingly, several things I tried didn’t work.

WebSockets isn’t there yet. The WebSockets demos I tried didn’t work on FireFox, even after turning WS on in about:config. They also didn’t work on Mobile Safari. Most of them fell back on Flash which doesn’t work on Apple hardware.

What did work was Socket.IO. This consists of client side JS to handle all the details of WS/long-polling/whatever on what browser you’re on. The Socket.IO folks intend for you to use server side JS in the form of Node.js, but that was not too interesting to me. In general I’m not convinced that there is enough sharing of code between client and server to make being hobbled by JS on the server side worth it. Also, my server needs to use some C APIs and I already had a Python C module to do so.

For Socket.IO with Python I found a cool project called TornadIO2 which is a Socket.IO adapter for Tornado. TornadIO2 is well integrated with Tornado and worked for me on the first try so I’m going with it. Tornado has an asynchronous interface with callbacks, which is not ideal and another reason why I’m not keen on Node.js, but there is a coroutine library built in that is based on Python generators.

Tornado also has good ZeroMQ integration. ZeroMQ is another good piece of kit that probably deserves its own blog post.

TornadIO2 gets the thumbs up from me. If you want to make a real-time web application with a mature language like Python and without screwing around with what should be a completely solved problem, check it out.

Written by hackingonempty

2012/01/13 at 9:24 am

Posted in Uncategorized

Leave a comment

Design a site like this with WordPress.com
Get started