Re: Bandwidth Allocation
- From: Peter Duniho <NpOeStPeAdM@xxxxxxxxxxxxxxxx>
- Date: Sat, 15 Sep 2007 10:43:20 -0700
salman wrote:
I am developing a server and I want to view and change the the clients
TCP connection bandwidth.
It's not really clear from your question what you want to do. However, assuming you want to do the possible rather than the impossible, the basic idea is simple:
* Displaying bandwidth requires that you count how many bytes have been transferred over a certain amount of time. How exactly to calculate this depends on what you want to display to the user. If you want to display total cumulative bandwidth, you'll just note the starting time for a transfer, count total bytes, and calculate the current bandwidth based on the ratio of the two.
If you want some sort of trailing average, you'll have to decide how often to update the average and for how many of those intervals back you want to calculate the average. One technique would be to keep a list of the byte count for each interval so that you can subtract the oldest byte count at each interval (the time part will be constant, based on the interval length and number).
Alternatively, you can do some sort of weighted average, in which all of your bytes are counted, but the most recent ones are weighted more heavily; this would allow you to calculate the trailing average without keeping track of all of the byte counts for some fixed number of intervals.
* Changing the bandwidth is a little more complicated, but not much. Obviously you can only restrict bandwidth; if the user wants more bandwidth than their network will support, you can't provide that.
For restricting bandwidth, you'll simply calculate a maximum number of bytes to transfer in some period of time, and when you reach that limit, wait until the period of time has expired. The period of time should be long enough that you can still send a reasonable amount of data in each "burst", but short enough that the network transfer is reasonably smooth.
The basic idea here is that if you have some requirement to not send data faster than, say, 100K per second then you include logic in your code that counts bytes sent and only allows 100K to go through for any one second interval (or 50K in a half second interval, or 200K in a two second interval, etc.).
Pete
.
- Follow-Ups:
- Re: Bandwidth Allocation
- From: salman
- Re: Bandwidth Allocation
- References:
- Bandwidth Allocation
- From: salman
- Bandwidth Allocation
- Prev by Date: SqlDataAdapter
- Next by Date: Re: Appending DataSet to an XML file
- Previous by thread: Re: Bandwidth Allocation
- Next by thread: Re: Bandwidth Allocation
- Index(es):
Relevant Pages
|