473,394 Members | 1,916 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Clocking transfer rate in c#

I'm using the HttpWebRequest/Response methods and I'm trying to figure
out how to calculate the effective transfer rare the file is being
received at (like you see in IE when you download something). I have
already learned how to do a "progress bar" type solution, which lets
me calculate percentages. This is different however, because rate
implies time.

I've tried making a timer that goes off once a second and then
applying (bytes downloded now - bytes downloaded last interval), I get
inaccurate speed (584 KB/s when it's more like 230 KB/s)

then I tried recording the ticks between 2 successive read calls in a
loop, dividing that by the number of ticks in a second, getting the
inverse of that and multiplying by 4 (bc my buffer is 4k). Still no
good

If anyone has any solutions I'd love to hear them. Thanks.
Nov 15 '05 #1
2 5468
I did something like this... It seems accurate

//SPEED STUF
counter++
int speed=lsize/counter
guid.labelSpeed.Text=speed.ToString()+" Kb/s"

this code is in my Timer1_Tick method, it is called every second. counter is type int and every second it is divided into the size of the file being downloaded to my hard drive. So if lsize = 126KB and counter =9; my download speed would be 14Kb/s (126/9=14). At least I think this is how it worked... I havent looked at this code in a longggg time

It sounds good to me. I just take the size of how much of the file has been placed on my drive, then divide the size by the amount of time it took to get that much. Yeah. this should work fine.
Nov 15 '05 #2
None <ma*******@hotmail.com> wrote:
I'm using the HttpWebRequest/Response methods and I'm trying to figure
out how to calculate the effective transfer rare the file is being
received at (like you see in IE when you download something). I have
already learned how to do a "progress bar" type solution, which lets
me calculate percentages. This is different however, because rate
implies time.

I've tried making a timer that goes off once a second and then
applying (bytes downloded now - bytes downloaded last interval), I get
inaccurate speed (584 KB/s when it's more like 230 KB/s)

then I tried recording the ticks between 2 successive read calls in a
loop, dividing that by the number of ticks in a second, getting the
inverse of that and multiplying by 4 (bc my buffer is 4k). Still no
good


Don't multiply by the buffer size - multiply by how many bytes you
actually received, which may not be the same as the buffer size.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: David C. Holley | last post by:
Real quick, please refresh my memory which one of the following preserves the information that was posted from a form? server.execute server.transfer response.redirect I need to have a...
0
by: Bob | last post by:
Hi. I'm developed a simple Transfer File program just to test the NetworkStream class. I want to know how can i get the transfer rate speed. Does someone know how to do it? And... what's the size...
9
by: c676228 | last post by:
Hi, I am new to this discussion forum. I started to post questions on this forum since this Jan. and got many good responses and I am very appreciated to those who are willing to help with their...
6
by: Programador | last post by:
I'm getting this error when running this program: Cannot calculate rate using the arguments provided Module Module1 Sub Main() Rate(360, -694.44444444444446, 244274.69178082192) End Sub
3
by: Peter Silva | last post by:
Hi folks, I have a need in a network data distribution application to send out data to folks who want it using the protocol of their choice. IŽd like it to support a variety of protocols and I...
2
by: mscdex | last post by:
I have a server application that accepts file transfers (utilitzing tcplistener) and was wondering how I would efficiently go about determining the calculate transfer rate while I am transferring...
5
by: madgunnercurz | last post by:
i currently have a database for tracking members arrival and exit times. however due to new demands my training centre are wanting a barcode system setup where all the user has to do is use a wedge...
4
by: Dimitrios Apostolou | last post by:
Hello list, I want to limit the download speed when using urllib2. In particular, having several parallel downloads, I want to make sure that their total speed doesn't exceed a maximum value. ...
1
by: whatazor | last post by:
Hi, how can I calulate transfer rate to a host , without using a file ? can ping module (written by Jeremy Hylton) be useful ?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.