473,396 Members | 1,757 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

NetworkStream.Write giving "forcibly closed" upon streaming

2
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:
Expand|Select|Wrap|Line Numbers
  1. _stream.Write(buffer, 0, buffer.Length)
  2.  
But if i try:
Expand|Select|Wrap|Line Numbers
  1. byte[] buffer = new byte[4196];
  2. int bytesRead = Body.Read(buffer, 0, 4196);
  3. while (bytesRead > 0)
  4. {
  5.     _stream.Write(buffer, 0, bytesRead);
  6.     bytesRead = Body.Read(buffer, 0, 4196);
  7. }
  8.  
I get the following exception: (sorry for the mess)
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.
Aug 19 '08 #1
1 4429
Plater
7,872 Expert 4TB
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:
Expand|Select|Wrap|Line Numbers
  1. GET /WAAF HTTP/1.1
  2. Accept: */*
  3. User-Agent: NSPlayer/11.0.5721.5145
  4. Host: wmc2.liquidcompass.cc
  5. X-Accept-Authentication: Negotiate, NTLM, Digest, Basic
  6. Pragma: version11-enabled=1
  7. Pragma: no-cache,rate=1.000,stream-time=0,stream-offset=4294967295:4294967295,packet-num=4294967295,max-duration=0
  8. Pragma: xPlayStrm=1
  9. Pragma: client-id=648480293
  10. Pragma: LinkBW=3480189, AccelBW=2147483647, AccelDuration=18000
  11. Supported: com.microsoft.wm.srvppair, com.microsoft.wm.sswitch, com.microsoft.wm.predstrm, com.microsoft.wm.startupprofile
  12. Pragma: playlist-gen-id=18965
  13. Pragma: xClientGUID={3300AD50-2C39-46c0-AE0A-FF8E16F71442}
  14. Pragma: stream-switch-count=2
  15. Pragma: stream-switch-entry=ffff:1:0 ffff:2:0 
  16. Accept-Language: en-us, *;q=0.1
  17.  
And the reply headers:
Expand|Select|Wrap|Line Numbers
  1. HTTP/1.1 200 OK
  2. Content-Type: application/x-mms-framed
  3. Server: Cougar/9.01.01.3814
  4. Date: Thu, 21 Aug 2008 18:18:30 GMT
  5. Pragma: no-cache, client-id=648480293, features="broadcast", timeout=60000, AccelBW=960000, AccelDuration=18946, Speed=1.000
  6. Cache-Control: no-cache, x-wms-stream-type="broadcast"
  7. Last-Modified: Sat, 30 Dec 1899 00:00:00 GMT
  8. Transfer-Encoding: chunked
  9. Supported: com.microsoft.wm.srvppair, com.microsoft.wm.sswitch, com.microsoft.wm.predstrm, com.microsoft.wm.fastcache, com.microsoft.wm.startupprofile
  10.  
Aug 20 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Matthew Louden | last post by:
The following ASP code yields the following error, but actually the new record is stored in database. The same error happens when the application deletes a record, such as sqlStmt ="delete from...
2
by: Dave | last post by:
These code generates the error: WebRequest request = WebRequest.Create("http://www.yahoo.com"); WebResponse response = request.GetResponse(); Here is the stack trace for the error: ...
0
by: jwalton | last post by:
I have a new Web Service (written in C#) that is giving me major problems. The Consumer application is written in VB.NET. When executed totally on localhost it works 100%. When standalone Web...
0
by: UDBDBA | last post by:
Hi: Currently, MAXFILOP cfg parameter is set to maximum value allowed for AIX 64bit: Max DB files open per application (MAXFILOP) = 1950 Still, we see "Database files closed"...
0
by: jack | last post by:
I have written a fairly simple c# server that uses asynchronous sockets. I have two different clients that connect and send/receive info from the server. Both exihibit this behaviour where...
0
by: lpinho | last post by:
Hi There, I've generated a C# file from a wsdl file using wsdl.exe utility. Then I created a console application and made a call to the method generated, first I got the error: "The request...
0
by: Steve | last post by:
Hi!, I'm using WebRequest to post a URL. But, sometimes, this tell me the error "The underlying connection was closed: A connection that was expected to be kept alive was closed by the server.". I...
1
gcoaster
by: gcoaster | last post by:
Hello, Access is accessing my patience! how does one filter just one form with a single combo box selection? I have a combo box named "cboCallStatus" unbound Row source type = Value...
4
by: Sin Jeong-hun | last post by:
I don't get the message so it's hard to debug that, but some of my clients report that they get "The underlying connection was closed unexpectedly" exception. According to this site (http://...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.