NetworkStream.Write giving "forcibly closed" upon streaming

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Almund
    New Member
    • Aug 2008
    • 2

    NetworkStream.Write giving "forcibly closed" upon streaming

    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:
    Code:
    _stream.Write(buffer, 0, buffer.Length)
    But if i try:
    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);
    }
    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.
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    Did you send the "connection : keep-alive" header?
    I'm not sure how streaming fits into the http protocol (I knwo it can be done, i've seen it) but the HTTP protocol specifies you give a content length, maybe there is something in that?

    EDIT:
    Streaming Request headers:
    Code:
    GET /WAAF HTTP/1.1
    Accept: */*
    User-Agent: NSPlayer/11.0.5721.5145
    Host: wmc2.liquidcompass.cc
    X-Accept-Authentication: Negotiate, NTLM, Digest, Basic
    Pragma: version11-enabled=1
    Pragma: no-cache,rate=1.000,stream-time=0,stream-offset=4294967295:4294967295,packet-num=4294967295,max-duration=0
    Pragma: xPlayStrm=1
    Pragma: client-id=648480293
    Pragma: LinkBW=3480189, AccelBW=2147483647, AccelDuration=18000
    Supported: com.microsoft.wm.srvppair, com.microsoft.wm.sswitch, com.microsoft.wm.predstrm, com.microsoft.wm.startupprofile
    Pragma: playlist-gen-id=18965
    Pragma: xClientGUID={3300AD50-2C39-46c0-AE0A-FF8E16F71442}
    Pragma: stream-switch-count=2
    Pragma: stream-switch-entry=ffff:1:0 ffff:2:0 
    Accept-Language: en-us, *;q=0.1
    And the reply headers:
    Code:
    HTTP/1.1 200 OK
    Content-Type: application/x-mms-framed
    Server: Cougar/9.01.01.3814
    Date: Thu, 21 Aug 2008 18:18:30 GMT
    Pragma: no-cache, client-id=648480293, features="broadcast", timeout=60000, AccelBW=960000, AccelDuration=18946, Speed=1.000
    Cache-Control: no-cache, x-wms-stream-type="broadcast"
    Last-Modified: Sat, 30 Dec 1899 00:00:00 GMT
    Transfer-Encoding: chunked
    Supported: com.microsoft.wm.srvppair, com.microsoft.wm.sswitch, com.microsoft.wm.predstrm, com.microsoft.wm.fastcache, com.microsoft.wm.startupprofile

    Comment

    Working...