By HTTP Streaming Comet, I mean the "forever iframe" / "forever xhr" variations that don't close the connection after data has been pushed from the server, as opposed to standard polling and long polling which close and resend a new request for every server push event.
I looked at the dojo.io.cometd package and it seems they only have polling implementations. I also found this example, but it doesn't seem to work in webkit even after a fair bit of tinkering (I got it to work everywhere else). This announcement from the safari blog seems to suggest that it's possible with xhr, but I couldn't find any code or documentation, nor I could get it to work.
Does anyone know of a technique, script, library or demo that accomplishes HTTP streaming comet in Webkit browsers (Safari and Chrome)?
Update
After a bit more tinkering, I found that there are two things that need to be done in order to get http streaming working in Safari via XHR:
- The response needs to have a Content-Type: multipart/x-mixed-replace
- The response needs to send a few "noise" characters before the browser begins to display updates consistently. I'm assuming this has something to do with filling some internal buffer.
Update 2
I finally got it to work in all browsers using an iframe technique. The caveat to the solution is that only WebKit-based browsers should receive the multipart/x-mixed-replace header.
According to Wikipedia, HTTP Streaming comet is supposed to be possible in every browser. "Page Layout with Frames that Aren't", Ajax: The Definitive Guide. O'Reilly Media, pp. 320. ISBN 0596528388, is the reference that is quoted for this information, so maybe this book has a suggestion on how to do this.
Also http://meteorserver.org/ has a demo which I just confirmed works in Chrome, of a client side library + a server which pushes data to the client.
It's definitely possible: GMail does it. If you watch the Resources section of the developer tools in the latest Webkit, you can watch it in action. They have a request called "bind" that stays open more or less indefinitely. My understanding is that when new mail arrives, it comes across that connection.
Although this is a old post, I did do some search and find the following articles really helpfull http://www.shanison.com/2010/05/10/stop-the-browser-%E2%80%9Cthrobber-of-doom%E2%80%9D-while-loading-comet-forever-iframe/
Yes.
You need to include a large amount (at least 256 bytes) of junk at the front of the response in order to get Safari to behave.