检测互联网连接是否繁忙
我们正在开发一个将安装在 PC 上的应用程序,它将执行一些后台上传和下载到我们的服务器的操作。其中一项要求是检测互联网连接当前是否繁忙(例如利用率高于 50%),如果繁忙,则需要退出并再次尝试。主要原因是确保应用程序不会干扰用户在玩游戏、观看在线电影或积极下载文件时的体验
经过谷歌的大量思考和研究,当然,我仍然没有找到一个好的关于如何实现这一点的方法,所以决定将其扔在这里。 该应用程序是用 C#、.NET 4.0 实现的,我正在寻找所有形式的响应 - 用 C# 或其他语言实现、伪逻辑或如何实现的方法 - 测量互联网流量利用率具有足够好的准确性的本地 PC。
为了避免重复工作,到目前为止我已经尝试过这些(以及为什么它们不适合)
- 使用 WMI 来获取网络统计信息。大多数 SO 帖子和解决方案都将此称为该方法,但它不符合我们的要求,因为根据网络接口容量(例如 1GB 以太网卡)测量发送/接收的字节以供使用,这将产生 LAN 流量的良好测量结果但不适用于互联网流量(实际互联网带宽可能仅为 8Mbps)
- 使用 .NET 网络信息统计或性能计数器 - 产生与上述类似的读数,因此具有相同的缺点
- 使用 ICMP (Ping) 并测量 RTT。有人建议,400 毫秒 RTT 被认为是网络繁忙的缓慢且良好的指示,但是我被告知,使用调制解调器(是的,我们必须支持这一点)的用户、使用反向代理或微波链路的 ping 值通常高于此值,因此这不是一个好的结果测量
- 开始下载一个已知文件并测量速度 - 这本身会产生我们试图避免的流量,而且如果经常进行此检查,我们的应用程序最终将创建大量互联网流量 - 这又不是理想的
- MOD:使用BITS - 这项服务可以在用户电脑上禁用,需要更改组策略并假设服务器是 IIS(具有自定义配置),在我们的例子中,我们的服务器不是 IIS
所以在这里,我很困惑并寻找一些建议。我突出显示了问题文本,这样你们就不会迷失阅读本文并想知道问题是什么。谢谢。
We are developing an application that will install on PC and it will perform some background upload and download to/from our server. One of the requirement is to detect if the internet connection is currently busy (say above 50% utilization) and if it is, it needs to back-off and try another time. The main reason is to ensure the app does not interfere with user experience if they are in the middle of gaming, watching online movie or aggressively downloading files
After much thinking and research on google and of course SO, I still haven't found a good way on how to implement this, so decided to throw this out here. The application is implemented in C#, .NET 4.0 and I am looking for all forms of responses - either implementation in C# or other languages, pseudo-logic or approach on how to achieve - measuring of internet traffic utilization on local PC with good enough accuracy.
To avoid duplication of effort, so far I have tried these (and why they aren't suitable)
- Use WMI to get network statistic. Most SO posts and solutions out there since to refer to this as the approach but it doesn't meet our requirement as measuring of bytes sent/received against network interface capacity (e.g. 1GB Ethernet Card) for utilisation will yield a good measure for LAN traffic but not for internet traffic (where the actual internet bandwidth might only be say 8Mbps)
- Use of .NET Network Information Statistics or performance counter - yield similar readings to the above hence have the same shortcomings
- Use ICMP (Ping) and measure RTT. It was suggested that 400ms RTT is considered as slow and good indication for busy network, however I was told that user with modem (yes we have to support that), use of reverse proxy or microwave link often get ping above that hence not a good measure
- Start downloading a known file and measure the speed - this itself generate traffic which we are trying to avoid, also if this check is done often enough, our application will end up creating a lot of internet traffic - which again not ideal
- MOD: Using BITS - this service can be disabled on user pc, requires group policy changes and assume server to be IIS (with custom configuration) and in our case our server is not IIS
So here it is, I'm all confuse and looking for some advice. I highlighted the question text so that you guys don't get lost reading this and wondering what the question is. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用 UPnP 查询路由器,并检索通过网络发送和接收的字节数。您可以继续检查路由器上的该值以确定活动是什么。遗憾的是,此功能似乎没有详细记录,但可以在 C# 应用程序中实现 UPnP 通信功能。您将需要使用 UDP 查询路由器(UPnP 发现),找到设备后,查询其功能,然后使用 WebClient (TCP) 查询 Internet 网关设备发送和接收的数据包数量。
You could use UPnP to query the router, and retrive the number of bytes sent and received over the network. You could keep checking this value on the router to determine what the activity is. Unfortunately this functionality doesn't seem to be well-documented, but it is possible to implement UPnP communication functionality within a C# application. You will need to use UDP to query for the router (UPnP discover), and once you have found the device, query its functionality, and then query the number of packets sent and received for the Internet Gateway Device using a WebClient (TCP).
您是否考虑过使用后台智能传输服务(BITS)。它已经被设计来完成这项工作:
和,
我不确定是否有托管接口(我可以看到对 Powershell Cmdlet 的引用),因此您可能必须使用 COM 互操作才能使用它。
Have you considered using Background Intelligent Transfer Service (BITS). It's designed to do this job already:
and,
I'm not sure if there's a managed interface to it (I can see reference to Powershell Cmdlets), so you might have to use COM interop to use it.
假设您的目标是 Windows PC(正如您所说,您正在使用 C# 进行开发),您是否查看过 BITS ,后台智能传输服务?
MSDN 和其他地方有如何使用 C# 连接到它的示例,例如 http:// /msdn.microsoft.com/en-us/magazine/cc188766.aspx
Making the assumption that you are targetting Windows PC's (as you said you were developing in C#), have you looked at BITS, the Background Intelligent Transfer Service?
There's examples of how to hook into it using C# on MSDN and elsewhere, e.g. http://msdn.microsoft.com/en-us/magazine/cc188766.aspx