There is a lot of bullshit buzz-speak about “COMET” floating about the internet these days. As best as I can tell, Comet is not an acronym for anything, but rather a play on the term “Ajax” (a related browser communication technique that, like Comet, shares its name with an abrasive cleaner.)
Though it seems that everything written on the subject of Comet is impossibly opaque, the concept is pretty damn simple. Comet is a way around the fact that HTTP is a stateless protocol (i.e., browsers request things, servers serve those things, and then the connection between the two immediately dies.) In order to get new information, browsers have to make requests. Heretofore, this has required applications that need to get frequently updated information to force the browser to “poll” the server at regular intervals to see if new information is available. There was no way for the server to let clients (browsers in this case) know that the new information was available as soon as it became available. Instead, the server had to wait for one of these polling requests to come in again.
This kind of problem is specialized, but important. The utility of being able to “push” data to clients as it becomes available is obvious for live chat, stock tickers, and election results, to name a few examples.
Now, thankfully computers are pretty fast these days, so the polling approach can scale quite nicely; to wit, Campfire, a live web-based chat application produced by our illustrious heros over at 37signals. Campfire does a fine business on a profit-per-request basis, thank you very much. But it does require throwing on some good equipment to support heavy user loads, and more seriously, it still suffers from an annoying lag between when a user types something and when it shows up in the chat window.
When we wrote our live chat application at Lovetastic.com, we chose one precarious solution to the problem to make latency a bit lower. We used Adobe Flash, which exists in most browsers but doesn’t suffer from the same need to communicate only via HTTP. That is, Flash can open stateful sockets with a server and keep the communication flowing both ways. Two problems with this: a) Flash is proprietary and stupid, and b) it requires us to home-brew our own buggy chat server in Python—Ruby’s network programming isn’t so hot. We’re web application programmers and we shouldn’t have to be solving these basic network programming challenges, reinventing the wheel just to get our own low-latency chat. Passing text to clients should be a simple problem, and we don’t see why we should be solving it as “end-user application developers” if you’ll pardon a silly turn of phrase.
Trouble is, the writing on Comet available on the internet up until very recently has been scarce at best and absurdly obscurantist at its worst. At the time we set out to create our live chat software, we couldn’t plow through the jargon-laden manifestos to get any practical information out of them. Equally, we weren’t keen on the prospect of having to code either Perl or Java in order to use some of the early comet servers being built.
But fortunately, now it looks like COMET is going to become a whole lot easier to do. This time its thanks to Jan Kneschke, the creator of the webserver lighttpd (which made YouTube possible), with whom we discussed this very prospect at this year’s RailsConf.
This will be a huge turning point for COMET… the point at which a developer can code a COMET app without building everything from scratch, a task that is not feasible for most (and was a prospect we certainly didn’t relish ourselves.)
As soon as Jan makes a version available, you can look to Lovetastic.com to be its test-bed.