Server-Sent Events
html5doctor.com
html5doctor.com
I wrote a very basic Node.js server to do this, which could in theory work well for 2-player games in the browser: https://github.com/ryanmcgrath/wii-js/blob/master/server.js
http://github.com/shinetech/eventserver
Basically you can post JSON messages via HTTP & they're streamed in real time to clients via the Server-Sent Events protocol.
This is a great, simple protocol with a dead-simple client-side API -- I can see it being really popular as browser support for SSE and CORS improves: http://www.w3.org/TR/cors/
Does anyone know if this would also end up with an open connection the whole time?
What we really need is some way of doing UDP via javascript, this would enable many things.
EDIT: Why would I want someone else able to track my taxi journey?
There's also some interesting benefits from my POV- it's effectively returning live data on the average mph on every street in the city. Relies on getting a decent number of users before being useful of course, but still.
Gratuitous plug for the site with more info: http://www.taxono.my/
The app also lets you search for destinations, gives you a time and fare estimate, split the total between friends, review your cab ride... while the tracking stuff is a central feature, it isn't the only one.
Testing battery drain is, by it's nature, a kind of time-consuming exercise. Given that it's a relatively small piece of functionality I just haven't gotten around to it yet.
I get the option of 1-way or 2-way communication built in. I don't have to worry about reconnects. It falls back all the way to IE5.5. It's usable in a number of languages and frameworks including node.js and Python.
What are the benefits of yet another framework?
Now that that's out of the way: Strictly speaking, WebSockets are "better" than SSE in that you can do everything you can do with SSE using WebSockets. However, the SSE protocol:
* Is plain HTTP, instead of adding on a separate protocol,
* Has an easy-to-generate text-based format,
* Does not require major upgrades to your server, and
* Can be emulated on non-conforming browsers using standard XHR's.
So when all you need to do in realtime is send data from the server to the client (remember, you can still use XHR's to call back to your server), SSE is far easier to implement both on the client and on the server.