Solved

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

Posted on 2009-05-05
8
1,854 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Problem to search 5 26
Recycle bin software for network mapped drives? 8 22
VB.NET Repostiory Pattern 7 17
How to join on ID, with prefix? 15 0
DECT technology has become a popular standard for wireless voice communication. DECT devices are not likely to be affected by other electronic devices and signals because they operate in a separate frequency-band.
In this article, I will show you HOW TO: Perform a Physical to Virtual (P2V) Conversion the easy way from a computer backup (image).
Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…
Viewers will learn how to connect to a wireless network using the network security key. They will also learn how to access the IP address and DNS server for connections that must be done manually. After setting up a router, find the network security…

863 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now