Solved

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

Posted on 2009-05-05
8
1,857 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 20 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 40 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 20 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
Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

 
LVL 83

Assisted Solution

by:CodeCruiser
CodeCruiser earned 40 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Possible fixes for Windows 7 and Windows Server 2008 updating problem. Solutions mentioned are from Microsoft themselves. I started a case with them from our Microsoft Silver Partner option to open a case and get direct support from Microsoft. If s…
A project that enables an administrator to perform actions within a user session context not just at the time of login but any time later on day(s) or week(s) later.
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…
Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…

827 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