我们如何使用C#限制控制台应用程序中的网络带宽 [英] How can we limit our network bandwidth in console application using C#

查看:144
本文介绍了我们如何使用C#限制控制台应用程序中的网络带宽的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对应用程序的需求是限制控制台应用程序中的带宽。

请根据需要提出建议。

提前致谢。



我尝试过:



到目前为止,我已经尝试了一些平均速度。我也试过Throttling Stream类,但没有找到相关内容,因为我是新手。

请建议我一些逻辑。



public static void ShowInterfaceSpeedAndQueue()

{

NetworkInterface [] adapters = NetworkInterface.GetAllNetworkInterfaces();

foreach(NetworkInterface adapter in适配器)

{

IPInterfaceProperties properties = adapter.GetIPProperties();

IPv4InterfaceStatistics stats = adapter.GetIPv4Statistics();

Console.WriteLine(adapter.Description);

Console.WriteLine(Speed ........................ .........:{0},

adapter.Speed);

Console.WriteLine(输出队列长度...... ..............:{0},

stats.OutputQueueLength);

}
秒表秒表=新秒表();

秒表。开始();

WebClient webClient = new WebClient();

string address =ftp:// speedtest:speedtest@ftp.otenet.gr/test10Mb.db;

var uri = new Uri(地址);

webClient.DownloadFile(uri,D:\\Sample3.db);

//Console.WriteLine(已过去的时间:{0},秒表。已经过了);

string time = Convert.ToString(stopwatch.Elapsed);

double timeInSecond = TimeSpan.Parse(time).TotalSeconds;

int speed = 10240 / Convert.ToInt32(timeInSecond);



Console.WriteLine(平均下载速度:+速度+kbps);

}

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");
}

推荐答案

也许StackOverflow上这个问题的答案符合你的需求。

C#中的带宽限制 - 堆栈溢出 [ ^ ]
Maybe the answers to this question on StackOverflow will fit your needs.
Bandwidth throttling in C# - Stack Overflow[^]


这篇关于我们如何使用C#限制控制台应用程序中的网络带宽的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆