How to obtain bandwidth and downloading rate

Hi all:

I want to develop a software like a peer_to_peer application in C#.But I don't quite know how to realize some functions such as getting a peer bandwidth,throttling and showing downloading rate.

I google it ,and find a article "How to do bandwidth Throttling using C# .Net code".

But the website require you to pay for registration. :=>(

can anyone tell me how to realize those functions or offer me some samples or some webs

Thanks a lot.



Answer this question

How to obtain bandwidth and downloading rate

  • Will Merydith

    Thanks all,

    I'll write my code for recording download speed and bandwidth as Alan stated.

    Thanks Alan specially.


  • Artje

    Thanks ,Alan.

    It is helpful to me .

    But can't we just invoke the window's api to get the transfer rate

    Is there have one


  • pessi

    There is no built in class to do this. It has to be done yourself (and it can be tricky so i've found ;) ).

    When sending data to another client you need send it in chunks of 1-5kB, in my application i choose 2kB chunks. Over 1 second intervals i totalled up how many chunks were sent and using that figure i calculated the average transfer rate. Then it's just a case of only sending a chunk of data when the calculated average transfer rate is less than the max allowed transfer rate.

    For accurate (ish) speeds i recorded the data transferred for each second and then averaged those over 10 seconds in order to get a good average transfer rate.

    Hopefully that makes sense to you.

  • Rudemusik

    As stated above there are no build in managed code APIs for this, but what you can do is P/Invoke to the QWave APIs. There is a rich suite of native APIs that do this for you. We are looking at exposing these through managed code in a future release.

  • tnfemme

    Well, as soon as you start P/Invoking native DLL's you've just restricted your application to windows-only, as opposed to windows/mac/linux/sega megadrive by running your app under Mono on those other platforms (mono works on windows too ;) ).

    Also, if you are writing a P2P application, then surely you'd need to provide rate-limiting to limit the max upload and download speed. In order to implement that you're implementing at least 80% of the necessary infrastructure to record download speed yourself :p

  • How to obtain bandwidth and downloading rate