Thought this was interesting enough to share; love to hear anyone's comments (been working in a void a bit on this).
One of the things that I recently have been pursuing is making mobile web apps that are more engaging by having them change behavior without user intervention based on some other action (be it the server or other users using the mobile web app). In researching this, I ran into the concept of Comet <http://en.wikipedia.org/wiki/Comet_(programming)> which is essentially what I was looking for.
The trick was to figure out how I was going to do this myself. BTW... The full source of all my various approaches to this are available as <https://github.com/larkintuckerllc>.
hellocomet: This was my first very simple attempt at writing an application using COMET.
hellochannel: After starting to fuss with all the issues, e.g., having to continually refresh the long poll, etc., decided to take another route and ended up using Google's Channel Service.
introduce: Once I started to actively build a real application using COMET with Google's Channel Service, I ended up changing tactics and went back to my original hellocomet code (essentially 20 lines of server code) and dealt with all the issues (ended up having about 200 lines of server code). This allowed me to completely get away the need to have some Java code running on Google's App Engine to front-end their Channel Service.
This is definitely an interesting topic. Nice...
For my money, I've been loving Socket.io. It's an extremely simple abstraction on this type of two-way communication. It prefers HTML5 Websockets but gracefully falls back through the ranks including long-polling and even a flash-based solution, I believe.
If you're not familiar with Websockets then they're definitely worth checking out, they are essentially a TCP socket for bi-directional communication. The connection is kept alive so passing event driven messages back and forth becomes trivial. I'm not up to speed on Google's Channel service but the nice part about Socket.io (or any other Websocket implementation for that matter) is that it's quite platform agnostic.
I wrote a demo app using the pre-1.0 version of Socket.io that allowed toggling of electrical outputs on a Rasberry Pi, in real time, over a network connection. Pretty simple stuff and was quick to implement. The server code (including http request handling-- no express needed ) clocks in at 55 lines. I included a testing stub so it can used without an actual Raspberry Pi.
In addition to Socket.io, there are some other Websocket layers worth checking out including Primus and ws. I've heard ws sports superior performance but haven't tested it yet.