views:

1729

answers:

6

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.

+3  A: 

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.

David Wees
+3  A: 

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.

Allen Pike
+2  A: 

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.

geocar
A: 

Great Job ! I run my Comet/Streaming on IE, Firefox and Opera and now thanks to this message also on Chrome.

OlekG, Poznan, Poland

A: 

Can we see some code examples? I set the header you suggested, but now I don't get any data into my iframe or xhr request. I have iframe streaming working in IE/Gecko, but webkit does not read any data until the request is complete

Jonathan
A: 

Although this is a old post, I did do some search and find the following articles really helps http://www.shanison.com/?p=237

jame