views:

526

answers:

3

Hello. I was wondering how I would be able to send out a continuous response stream without closing it eventually. To better explain my question, think of the asp page as a proxy relaying a third party stream from a different source (audio stream or video stream broadcasted by another source)

Obviously, Response.Write() or Response.BinaryWrite() constrain me to a predefined source.

Thanks in advance.

+2  A: 

You can disable response buffering using the BufferOuput property of the current HttpResponse object.

Ken Browning
Thanks for the feedback. There's also the issue of actually outputting the response in that fashion, since the methods provided by the Response object only allow for predefined byte arrays and such. Basically I would need two concurrent objects running, one that would be the reader and the other one writing the contents that were read from the reader to the output.
mtranda
+1  A: 

i could imagine disabling Response Buffering or using Response.Flush() regularly should do the trick.

By setting up an IHttpHandler you just make sure your Process() method never finishes executing, thus will your request never finish either.

BurningIce
about your constrain to a predefined source you need to set up 1. reading from stream2. save to buffer3. writer buffer to response (BinaryWrite)4. flush the Response5. repeat from step 1
BurningIce
Thanks for that. I've just written to Ken Browning about having a need for two concurrent objects running, and it seemed a bit overkill for a webpage. On the other hand, I'm wondering about whether doing it the way you mentioned it will lose any packets (since it's a live stream), although it shouldn't be that big of an issue, especially if I was to do it in small chunks.
mtranda
Using the WebClient and OpenRead method, which returns a Stream, it will buffer the incoming live stream, until you pop off the data using the Read() method on the Stream.
BurningIce
of course you need to use the OpenReadAsync method and subscribe to the OpenReadCompleted event which will give you access to the underlying stream which you can read from.
BurningIce
Thanks a bundle. This should be quite fun to play with. Haven't had the chance to use async operations yet since I had no need for them ... until now.Also, I'm not asking for the complete solution, since I actually enjoy learning :)
mtranda
A: 

In addition to trying Response.Buffer=false and calls such as Response.Flush(), make sure you aren't using a Proxy Server/Http Debugger while testing. I failed to get this working until I shut down Fiddler.

JoeCoder