Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

VB.NET problem using WebRequest.GetResponseStream to download a big file in GRPS/3G

Posted on 2009-05-05
8
Medium Priority
?
1,873 Views
Last Modified: 2013-12-21
Any Experts Please Help!
I am using the following VB code in Window Mobile to download a 1M file from the web server.  It works very fast on Wi-Fi mode, less than 5 seconds, using my code or Internet Explorer, no discernable different.    
However, on GPRS/3G mode: it takes about 5 to 10 minutes to download the same file in IE, but my VB code took 17 or sometime 40 minutes to download the file.  The first 500K seems fast in about 4 minutes, still a bit slow when compare to IE, but the last 500 was so slow.  What am I missing?  Please help.  Thanks!
Request = System.Net.WebRequest.Create(sURL)
            Response = Request.GetResponse
            ResponseStream = Response.GetResponseStream
            Dim numBytesToRead As Integer = CInt(Response.ContentLength)
            Dim bytes(Response.ContentLength) As Byte
            Dim numBytesRead As Integer = 0
            While numBytesToRead + 1 > 0
                Dim n As Integer = ResponseStream.Read(bytes, numBytesRead, numBytesToRead)
                 If n = 0 Then
                    Exit While
                End If
                numBytesRead += n
                numBytesToRead -= n
            End While

Open in new window

0
Comment
Question by:eddielao
8 Comments
 
LVL 96

Assisted Solution

by:Bob Learned
Bob Learned earned 80 total points
ID: 24315297
I have no idea, but you should be able to use a StreamReader to read all the bytes, without use a While statement.  I am not sure if it will help your issue, but it might be a good place to start.
0
 
LVL 83

Assisted Solution

by:CodeCruiser
CodeCruiser earned 160 total points
ID: 24315306
I think you should read a 1024 or 2048 etc number of bytes at a time consistently. Change the loop to keep reading 2048 (for example) bytes at a time until it reads all.
0
 
LVL 15

Assisted Solution

by:oobayly
oobayly earned 80 total points
ID: 24315527
I was going to recommend the WebClient but of course that's not available. How many times have you compared the download times? You're obviously only using a GPRS connection as the speeds are between 27kBit/s & 14kBit/s which is low even for GPRS. It sounds like the connection is a bit flaky on GPRS.

Also, how about reading in blocks of 2k bytes at a time, or writing direct to a FileStream rather than memory. Not convinced it'll make a difference as it seems like a connection issue rather than lack of resources.
0
NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

 
LVL 83

Assisted Solution

by:CodeCruiser
CodeCruiser earned 160 total points
ID: 24315680
The loop used currently keeps incrementing the number of bytes being read as it advances. First time it reads 1 byte, then 2, then 3 ....
Keep the number of bytes to read each time fixed.
0
 

Accepted Solution

by:
eddielao earned 0 total points
ID: 24317381
I changed the code to read 2K at a time and it is doing the same things......

my code was doing the opposite of what CodeCruiser suggested, it was reading the full file size, then the remaining........ until the full file is done!  
0
 

Author Comment

by:eddielao
ID: 24915675
Thanks!
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Windows Server 2003 introduced persistent Volume Shadow Copies and made 2003 a must-do upgrade.  Since then, it's been a must-implement feature for all servers doing any kind of file sharing.
Unable to change the program that handles the scan event from a network attached Canon/Brother printer/scanner. This means you'll always have to choose which program handles this action, e.g. ControlCenter4 (in the case of a Brother).
This video Micro Tutorial explains how to clone a hard drive using a commercial software product for Windows systems called Casper from Future Systems Solutions (FSS). Cloning makes an exact, complete copy of one hard disk drive (HDD) onto another d…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question