473,657 Members | 2,436 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

NetworkStream.W rite giving "forcibly closed" upon streaming

2 New Member
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)
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.
Aug 19 '08 #1
1 4448
Plater
7,872 Recognized Expert Expert
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
46887
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 test where username='2323'" Any ideas? Thanks! <% Dim objRS, sqlStmt Set objRS = Server.CreateObject ("ADODB.Recordset") sqlStmt = "insert into test VALUES ('2341', '2341');"
2
5549
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: WebException: The underlying connection was closed: Unable to connect to the remote server.] System.Net.HttpWebRequest.CheckFinalStatus() +673
0
1669
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 Service is executed on production server using Form-based ASP.NET test mode, it works 100%. When Web Service is executed on production server with Consumer on localhost it works 100%. However when Web Service and Consumer are both executed totally on...
0
1550
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" increasing gradually: Database files closed = 825 DGTT's are used heavily by application and most of the files closed
0
1380
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 everything will work fine for a long while, but eventually the OnDataReceived callback method throws an exception on the EndReceive method, with socket exception "An existing connection was forcibly closed by the remote host". I am reasonably sure the...
0
2623
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 failed with HTTP status 407: Proxy Access Denied." Then I added a proxy validating and proxy credentials and got this:
0
1672
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 don't know why!!. This worked perfect in .NET 1.1, but in .NET 2.0, I has this behavior. Thanks!
1
2259
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 List values; OPEN, CLOSED
4
4563
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:// www.dotnetspider.com/resources/2596-e-underlying-connection-was-closed-A-connection.aspx), it's a bug of .NET 2.0, and the author suggests that we use KeepAlive=false until Microsoft fixes it. It seems like almost 5 years have passes since the...
0
8310
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8826
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8503
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7330
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6166
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4306
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1955
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.