Click here to Skip to main content
15,904,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi to all..

Does any body knows how to find out how much bandwidth is uploading per kb/sec based on net speed using c#?
Does any body knows how to find out how much bandwidth is downloading kb/sec based on net speed using c#?
and how to restrict that bandwidth based on kb/sec..
if anybody knows please let me know the solution..
Posted
Updated 17-Nov-11 1:51am
v2

1 solution

To calculate the bandwidth in use you must use the NetworkInterface class in the System.Net.NetworkInformatio namespace, and calculate it like this:-

C#
IPv4InterfaceStatistics stats = NetworkInterface.GetAllNetworkInterfaces()[0].GetIPv4Statistics();
            int bytesSentSpeed = 0;
            int bytesReceivedSpeed = 0;
            bytesSentSpeed = (int)(stats.BytesSent - bytesSentSpeed) / 1024;
            bytesReceivedSpeed = (int)(stats.BytesReceived - bytesReceivedSpeed) / 1024;


AS far as limiting the bandwidth, I don't think it is possible in C#.

Hope this helps
 
Share this answer
 
Comments
narmadhalilly 19-Nov-11 4:58am    
my application like this:
how to calucate the bndwidth based on per kb/sec

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900