title: Streaming any image to HTML client?
body: <p>The use case is to reference an image URL (e.g. &lt;img src=...&gt;) in an HTML document which would be viewed by a browser or an email client, and have the image reflect the current state as determined by the server. The image would be dynamically computed and created by the back-end, e.g. a servlet, at regular intervals, e.g. every minute. It's kind of like a video-feed, but with a very poor frame rate (one frame per minute). ;)</p>
  
  <p>I guess there are at least two key assumptions that must be satisfied here:</p>
  
  <ol>
  <li><p>The back-end producing the image must be able to send the initial version of the image, then subsequent versions of the image, e.g. in a compute-send-sleep loop, without the client closing the connection. The back-end would keep the HTTP connection to the client open and keep sending new versions until the client closes the connection, e.g. because it's no longer displaying the document.</p></li>
  <li><p>The client fetching the image will detect that the back-end keeps sending new versions of the image and redraw it. I'm not sure if the server can explicitly signal this to the client, e.g. set a keep-alive response header or something to that effect -- or perhaps it's not even needed give that the server will keep the connection open.</p></li>
  </ol>
  
  <p>Are these assumptions reasonable? For the back-end I'll use a servlet as proof of concept, while the front-end will be a browser like Firefox and an email client like Thunderbird.</p>
  
  <p>I'm not quite sure how the server would signal the client that the previous image is obsolete and can be discarded and the new one should be received and redrawn, but perhaps it's simply a matter of flushing and resending the new data? Any pointers on that would be greatly appreciated as well.</p>
  
  <p>Using something like an animated gif won't work as I won't be able to know ahead of time what the image will be. In other words, I can't pre-compute the sequence of images and send it once.</p>