Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

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,864 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Create the perfect environment for any meeting

You might have a modern environment with all sorts of high-tech equipment, but what makes it worthwhile is how you seamlessly bring together the presentation with audio, video and lighting. The ATEN Control System provides integrated control and system automation.

 
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

In this post we will be converting StringData saved within a text file into a hash table. This can be further used in a PowerShell script for replacing settings that are dynamic in nature from environment to environment.
Know the reasons and solutions to move/import EDB to New Exchange Server. Also, find out how to recover an Exchange .edb file and to restore the file back.
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

721 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