Click here to Skip to main content
15,888,330 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My need for the application is to limit the bandwidth in the console application.
Please suggest something according to the need.
Thanks in advance.

What I have tried:

I have tried something to get the average speed till now. I also tried Throttling Stream class, but didn't found something related as i am new to this.
Kindly suggest me some logic for that.

public static void ShowInterfaceSpeedAndQueue()
{
NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces();
foreach (NetworkInterface adapter in adapters)
{
IPInterfaceProperties properties = adapter.GetIPProperties();
IPv4InterfaceStatistics stats = adapter.GetIPv4Statistics();
Console.WriteLine(adapter.Description);
Console.WriteLine(" Speed .................................: {0}",
adapter.Speed);
Console.WriteLine(" Output queue length....................: {0}",
stats.OutputQueueLength);
}
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
WebClient webClient = new WebClient();
string address = "ftp://speedtest:speedtest@ftp.otenet.gr/test10Mb.db";
var uri = new Uri(address);
webClient.DownloadFile(uri, "D:\\Sample3.db");
//Console.WriteLine("Time elapsed: {0}", stopwatch.Elapsed);
string time = Convert.ToString(stopwatch.Elapsed);
double timeInSecond = TimeSpan.Parse(time).TotalSeconds;
int speed = 10240 / Convert.ToInt32(timeInSecond);

Console.WriteLine("Average Download speed: " + speed + "kbps");
}
Posted
Updated 6-Jun-16 20:32pm

1 solution

Maybe the answers to this question on StackOverflow will fit your needs.
Bandwidth throttling in C# - Stack Overflow[^]
 
Share this answer
 

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