I'm trying to implement streaming over http and got stuck with a problem trying to send chunks of data using the .Net NetworkStream object.
All works fine as long as I send the entire data in one invocation to the NetworkStream, like:
Expand|Select|Wrap|Line Numbers
- _stream.Write(buffer, 0, buffer.Length)
Expand|Select|Wrap|Line Numbers
- byte[] buffer = new byte[4196];
- int bytesRead = Body.Read(buffer, 0, 4196);
- while (bytesRead > 0)
- {
- _stream.Write(buffer, 0, bytesRead);
- bytesRead = Body.Read(buffer, 0, 4196);
- }
HttpRequestParser.ParseMessage => HttpClientContextImp.OnRequestCompleted => HttpServer.SetupRequest | Failed to respond on message with Internal Server Error: System.IO.IOException: Unable to write data to the transport connection: An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
at System.Net.Sockets.Socket.Send(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
at System.Net.Sockets.NetworkStream.Write(Byte[] buffer, Int32 offset, Int32 size)
--- End of inner exception stack trace ---
at System.Net.Sockets.NetworkStream.Write(Byte[] buffer, Int32 offset, Int32 size)
Only difference I can see is that the stream sends the data in bits (I do send some http headers in both case but i´ve stripped some of that code since its productioncode). Another twist is that it works when sending the code to for example Firefox but when trying to stream it to ie embedded data in a webpage it breaks.
Any help would be greatly appreciated.