I'm trying to come up with a practical client-side (JavaScript) implementation for Comet. http://en.wikipedia.org/wiki/Comet_(programming)) talks about the theory but I'm having a tough time trying to find an implementation that works. I understand there's a good servers-side requirement here too but I'm only interested in the client-side part of it.
Specifically the questions I am trying to answer are -
- How do I detect in JavaScript that a connection has been successfully established. For eg. if I were to use the script tag long polling method and the browser could never get to the server, how would I know ?
- When long polling, if there's no response from the server the browser will eventually fall into the "request timed out" state. How do I detect this in Javascript and re-establish the long poll?
- How do I ensure my technique works across browsers? Basically I want to know the right mix of methods (script tag, xhr etc.) that would cover most browsers.
I tried looking for Comet frameworks but every framework I found (CometD, Atmosphere) etc. comes with a server-side implementation as well and makes the client-side deal transparent to the user. I'm however trying to find out how they achieve the client-side feat. I have my own server implementation and protocol.