By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,257 Members | 925 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,257 IT Pros & Developers. It's quick & easy.

best way to calculate transfer rate?

P: n/a
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 the
file. The Sub where the transfer actually takes place is called
asynchronously.

The (psuedo) code in the Sub goes something like this:

While byteCount < filesize
bytesRead = Bytes read from NetworkStream
Write bytes just read in to file via a FileStream object
byteCount += bytesRead
Update progress bar for transfer
End While

I have tried somehow using a TimeSpan object to attempt to calculate
after I update the progress bar, but that has proved to not only work
for me, but it makes the transfer rate display not update evenly.

I've looked on the net for any samples of this, but could not turn up
anything.

Aug 20 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hello ms****@gmail.com,

You'll want to run an average over a chunk of time.. I would suggest somewhere
around 5-10 seconds.
You can take a look at performace counters for high precision timers..

bytedReceived / unitsOfTime = bytesPerUnit..
TotalBytes / bytesPerUnit = ETAinUnits

-Boo
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 the
file. The Sub where the transfer actually takes place is called
asynchronously.

The (psuedo) code in the Sub goes something like this:

While byteCount < filesize
bytesRead = Bytes read from NetworkStream
Write bytes just read in to file via a FileStream object
byteCount += bytesRead
Update progress bar for transfer
End While
I have tried somehow using a TimeSpan object to attempt to calculate
after I update the progress bar, but that has proved to not only work
for me, but it makes the transfer rate display not update evenly.

I've looked on the net for any samples of this, but could not turn up
anything.

Aug 20 '06 #2

P: n/a
Thanks for the suggestion. Only question left is, what would be the
best way to time a transfer this way, taking into account that multiple
transfers across multiple connections can all be happening at once (the
sub containing the actual file transfer code is called asynchronously)?

For example, if I were to use a Timer, I'd have to create a new Timer
object for each connection, but then somehow have an Elapsed event that
could be called from any of those Timers, and would update the transfer
rate accordingly. That's what I'm confused about. Or do the high
precision timers you're talking about not utilize events?

Thanks again

GhostInAK wrote:
Hello ms****@gmail.com,

You'll want to run an average over a chunk of time.. I would suggest somewhere
around 5-10 seconds.
You can take a look at performace counters for high precision timers..

bytedReceived / unitsOfTime = bytesPerUnit..
TotalBytes / bytesPerUnit = ETAinUnits

-Boo
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 the
file. The Sub where the transfer actually takes place is called
asynchronously.

The (psuedo) code in the Sub goes something like this:

While byteCount < filesize
bytesRead = Bytes read from NetworkStream
Write bytes just read in to file via a FileStream object
byteCount += bytesRead
Update progress bar for transfer
End While
I have tried somehow using a TimeSpan object to attempt to calculate
after I update the progress bar, but that has proved to not only work
for me, but it makes the transfer rate display not update evenly.

I've looked on the net for any samples of this, but could not turn up
anything.
Aug 20 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.