Hi,
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:
But if i try:
I get the following exception: (sorry for the mess)
HttpRequestPars er.ParseMessage => HttpClientConte xtImp.OnRequest Completed => HttpServer.Setu pRequest | Failed to respond on message with Internal Server Error: System.IO.IOExc eption: Unable to write data to the transport connection: An existing connection was forcibly closed by the remote host. ---> System.Net.Sock ets.SocketExcep tion: An existing connection was forcibly closed by the remote host
at System.Net.Sock ets.Socket.Send (Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
at System.Net.Sock ets.NetworkStre am.Write(Byte[] buffer, Int32 offset, Int32 size)
--- End of inner exception stack trace ---
at System.Net.Sock ets.NetworkStre am.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.
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:
Code:
_stream.Write(buffer, 0, buffer.Length)
Code:
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); }
HttpRequestPars er.ParseMessage => HttpClientConte xtImp.OnRequest Completed => HttpServer.Setu pRequest | Failed to respond on message with Internal Server Error: System.IO.IOExc eption: Unable to write data to the transport connection: An existing connection was forcibly closed by the remote host. ---> System.Net.Sock ets.SocketExcep tion: An existing connection was forcibly closed by the remote host
at System.Net.Sock ets.Socket.Send (Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
at System.Net.Sock ets.NetworkStre am.Write(Byte[] buffer, Int32 offset, Int32 size)
--- End of inner exception stack trace ---
at System.Net.Sock ets.NetworkStre am.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.
Comment