Solved

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

Posted on 2009-05-05
8
1,850 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
Give your grad a cloud of their own!

With up to 8TB of storage, give your favorite graduate their own personal cloud to centralize all their photos, videos and music in one safe place. They can save, sync and share all their stuff, and automatic photo backup helps free up space on their smartphone and tablet.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
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…
The viewer will learn how to successfully create a multiboot device using the SARDU utility on Windows 7. Start the SARDU utility: Change the image directory to wherever you store your ISOs, this will prevent you from having 2 copies of an ISO wit…

746 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

13 Experts available now in Live!

Get 1:1 Help Now