473,395 Members | 1,456 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,395 software developers and data experts.

Why Would ResponseStream().Read return zero bytes when not at end offile?

Greetings,

I have an app that uses HttpWebRequest to download a rather large file
(100 MB). I have a while loop set up so that it reads 4096 bytes at a
time from the ResponseStream() until it reads zero bytes. The odd
thing is that for some of the people using my app, the Read() function
from the ResponseStream() will return zero bytes even though it has
not read the enter ResponseStream(). I know it hasn't read the entire
stream because I do a ResponseStream().ContentLength and get the size
of the stream (and record it) before I start reading data, then I also
record how many bytes I've read.

Any idea why this would be happening? And any suggestions on how to
get around?
Jan 11 '08 #1
4 3570
Rymfax wrote:
I have an app that uses HttpWebRequest to download a rather large file
(100 MB). I have a while loop set up so that it reads 4096 bytes at a
time from the ResponseStream() until it reads zero bytes. The odd
thing is that for some of the people using my app, the Read() function
from the ResponseStream() will return zero bytes even though it has
not read the enter ResponseStream(). I know it hasn't read the entire
stream because I do a ResponseStream().ContentLength and get the size
of the stream (and record it) before I start reading data, then I also
record how many bytes I've read.

Any idea why this would be happening? And any suggestions on how to
get around?
It sounds weird.

The docs are rather clear:

#Return Value
#The total number of bytes read into the buffer. This can be less than
#the number of bytes requested if that many bytes are not currently
#available, or zero (0) if the end of the stream has been reached.

Is the file in question public available so we can try ?

Arne
Jan 11 '08 #2
I don't know why it is dropping ,but if the web-server supports it,
you could attempt to resume by adding a RANGE header to the request
and re-sending? (i.e. from byte {large number} onwards...)

Marc
Jan 11 '08 #3
Would the amount that you actually can download correspond to about four
megabytes?

--
--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
"Rymfax" <cw*****@bigbangllc.comwrote in message
news:c6**********************************@k39g2000 hsf.googlegroups.com...
Greetings,

I have an app that uses HttpWebRequest to download a rather large file
(100 MB). I have a while loop set up so that it reads 4096 bytes at a
time from the ResponseStream() until it reads zero bytes. The odd
thing is that for some of the people using my app, the Read() function
from the ResponseStream() will return zero bytes even though it has
not read the enter ResponseStream(). I know it hasn't read the entire
stream because I do a ResponseStream().ContentLength and get the size
of the stream (and record it) before I start reading data, then I also
record how many bytes I've read.

Any idea why this would be happening? And any suggestions on how to
get around?
Jan 11 '08 #4
On Fri, 11 Jan 2008 13:06:26 -0800, Rymfax <cw*****@bigbangllc.comwrote:
[...]
It is possible that it is reading zero bytes because the connection is
closing prematurely, but this is suppose to generate an exception
That's not true. You'll get an exception if the connection is _reset_,
but if it's simply closed then you get a 0 byte receive.
which I check for (I actually check for any exception).
So I don't
know what could be causing the ResponseStream to return zero bytes if
it hasn't reached the end of the content (according to the
ContentLength anyway).
As I said, there is no network requirement that the number of bytes
delivered by the server before closing the connection is identical to the
number of bytes the server advertised in the HTTP response. The
advertised length is just that: an advertisement. The network side of
things doesn't enforce it.

One would expect a correctly-behaving HTTP server to provide the bytes as
advertised, but servers don't always behave, and on top of that some ISPs
are known to mess with TCP connections, including doing something like
closing it for no good reason.
I've already coded in a re-check for when this
happens, but I was hoping to figure out WHY it is happening.
That's an admirably goal. But the only way you can do that is by doing
some debugging. You need to monitor the network traffic at both ends and
figure out who is closing the connection. Once you've identified that,
then you can look at why. Unfortunately, a vague problem description is
not enough information for anyone else in this newsgroup to answer the
question. Only first-hand knowledge will do.

Pete
Jan 12 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: RJN | last post by:
Hi I have a user defined data type which implements IComparable interface and has an implementation for the CompareTo method. Public Class MyDataType Implements IComparable --Private...
2
by: | last post by:
Hi All, How can I return a row when the condition is not met for example simplified SELECT Name,SUM(Cost) AS T FROM DB WHERE Name="+Name +" GROUP BY Name this works fine but I ned it to return...
0
by: phplasma | last post by:
Hey, I am currently attempting to implement a multi-threaded C# socket, using SSL (.pem file/certification/private key combo) server using Visual Studio C# Express. I have successfully made...
22
by: semedao | last post by:
Hi , I am using asyc sockets p2p connection between 2 clients. when I debug step by step the both sides , i'ts work ok. when I run it , in somepoint (same location in the code) when I want to...
2
by: Brent Rogers | last post by:
I am having trouble with the DeflateStream.Read() method. For some reason it wants to return Zero. I have this set of classes: =================== using System; using...
64
by: Robert Seacord | last post by:
The C standard doesn't say anything about what happens when you call realloc with a size argument of 0. Both glibc and openbsd appear to return a valid pointer to a zero-sized object.. e.g. the...
7
by: =?Utf-8?B?aXdkdTE1?= | last post by:
hi, im attempting to create an intellisense type form and have hit a roadblock. I need the form to return (like the ShowDialog method returns the dialog result) the value that was selected when the...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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...
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
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.