
Hi there, I've been experimenting a bit with the new EventSource API ( http://hacks.mozilla.org/2011/06/a-wall-powered-by-eventsource-and-server-se... ). EventSource looks like a much nicer alternative to WebSockets in all the cases where the connection doesn't really need to be bi-directional (ajax request to push to the server, Event Source to push to the client). It doesn't require a new protocol and should be trivial to pass through HTTP aware load balancers, cache proxies and so on. Have been trying to get either Snap or Warp to serve up an EventSource endpoint, but so far I'm stuck at not being able to get any of them to actually write to the response body before the request is all over. Here's some example code: Snap based: https://gist.github.com/1174102 WAI/Warp based: https://gist.github.com/1174632 The code is mostly the same apart from the glue to the web server. In both cases I'm trying a silly enumerator that gets messages from the keyboard and pass them to the iterator. It all compiles and kinda works, but nothing gets written to the response before I end the enumeration with "q". Any hints on what I'm doing wrong? Or any example code for controlling writes to the response body during a long request? Cheers, Mathias

Hi Mathias, I recently wrote exactly what you're looking for with Snap, and you can get the code at https://github.com/cdsmith/gloss-web/blob/master/src/EventStream.hs Let me know if that answers your question. I imagine something analogous would work with WAI, since I think it uses the same enumerator/builder pattern; but I'm not familiar with the details of WAI. The key to writing the request incrementally is to set an enumerator with appropriate flushing. -- Chris Smith
participants (2)
-
Chris Smith
-
Mathias Biilmann Christensen