Playing with Comet
I've been having a bit of a tinker with Comet, a complementary technology to Ajax. The concept isn't new: it's essentially socket programming but instead of sockets it's done over HTTP with a web browser and a standard web server. The idea has been around for a number of years in various guises but has gathered steam recently in "Web-2.0" (don't shoot me! At least we all know what I'm talking about!) circles so I thought I'd give the tyres a bit of a kick for myself.
My first impression is that, because Comet is relatively new, there's a lot of experimentation still going on. Because of this there isn't a dominant standard and documentation seems to be very limited. I found that I couldn't just grab some library code, drop it in a folder and move on to making it do something useful; I had to roll up my sleeves and get stuck in to the plumbing. Part of the reason for this is because Comet does things that neither HTTP, HTML, Javascript or web browsers were originally intended to do. It also had something to do with the fact that I'm predominantly a LAMP guy and Comet server software suffers less from the inherent limitations of the concept by being built with other languages like Python, Ruby or Java. Lighter-weight servers like Jetty also seem to save themselves some headaches over Apache which is fine for testing or if you run your own production servers, but there are likely to be limitations on most shared hosts and the technology is unlikely to be popular with many of the ISPs who run them because of the scalability issues.
Maybe Comet isn't really appropriate for use on a shared host due to the higher demands of maintaining a connection with every client but I don't see it taking off in a big way unless Joe web developer can use it on his free or shared host without hassle. What I think more likely is that we'll see 3rd party companies offer hosting of these services, much like companies who host chat rooms and voip systems have for many years already. It might be interesting to see Comet piggy-back on a more established system like Jabber, IRC, Amazon's SQS or Twitter but whether any of those will happen remains to be seen. Certainly, each of them has some of the facilities in place already so I don't imagine it would be unachievable. Google is also one of the best-known large-scale users of Comet and they have a good record of sharing with developers so maybe we'll see something from them at some point.
For my own purposes, I ended up hacking something together quickly with PHP and jquery using the long-poll method. Effectively, this involves connecting to the server using XHR, waiting for something to happen then closing the connection and re-polling the server. Connect, wait, process, disconnect. Rinse, wash and repeat - ad infinitum. I don't imagine this code setting the world on fire but it seems to work well enough on a standard LAMP (Apache/PHP5) setup and I reckon it could be the basis of a reasonable service as long as the site isn't too heavily subscribed.
Download all the files as a zip and have a play with it if you feel inclined. Just unzip, drop in your web root and make log.txt writable. The code should work on any PHP5 server and uses jQuery for ajax and some minor interface silliness. It's been tested briefly in Firefox and Safari but it isn't pretty and I make no guarantees whatsoever to its safety or suitability, so have fun!