捕获网络状态变化事件

发布于 2024-08-18 11:24:15 字数 226 浏览 11 评论 0原文

我试图在互联网连接丢失后重新建立时获取事件。这是我正在开发的数据传输软件。如果我在数据传输过程中失去网络,我希望在网络恢复时收到通知并自动继续传输。

我当然可以创建一个单独的线程并使用计时器偶尔检查一次网络,但也许有更好的选择。

我主要使用 C++(而不是 .net)为 Windows 进行开发。

我还可以使用 wxwidgets (我将它用于 GUI),但我怀疑它是否提供任何相关功能。

I am trying to get events when the internet connection is reestablished after it is lost. It is for a data transfer software that I am developing. If I lose the network during data transfer, I would like to be notified when it is back and continue the transfer automatically.

I can of course create a separate thread and check the network once in a while with a timer, but maybe there is a better option out there.

I am developing for windows mainly, in C++ (not .net).

I can also use wxwidgets (I use it for GUI) but I doubt it offers any related functionality.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

二手情话 2024-08-25 11:24:15

您可能想查看系统事件通知服务器 (SENS) API

我实际上没有使用过它,但它似乎提供了您正在寻找的事件。

编辑:

WMI 似乎拥有您需要的有关各种网络连接和状态更改的所有信息。它还具有可用于获取通知的异步事件模型。我想,诀窍是生成正确的 WMI 查询来获取您想要的信息。这个 blog 看起来像是正确的查询类型,并且此 MSDN 解释了如何异步处理事件。

You might want to check out the System Event Notification Server (SENS) API.

I have not actually used it, but it seems like it supplies the events your looking for.

EDIT:

WMI appears to have all the information you need about various network connectivity and state changes. It also has an asynchronous event model that can be used to get notifications. The trick is, I suppose, generating the proper WMI query to get the information you want. This blog looks like the right type of query, and this MSDN explains how to handle the events asynchronously.

热风软妹 2024-08-25 11:24:15

我不知道您使用哪种协议以及您是否可以控制目的地,但在这种情况下,目的地可以轮询重试。目的地最清楚它所接收到的内容,因此它可以给出接收到的字节数作为重传的偏移量。

I don't know which protocol you use and whether you can control the destination, but in that case, the destination can poll for a retry. The destination knows best what it has received, so it can give the received number of bytes as offset for the retransmission.

音盲 2024-08-25 11:24:15

此 MSDN 链接提供了如何使用 COM 捕获 WMI 事件的非常详细的示例。该示例实际上并未捕获网络事件 - 但我相信,如果您插入正确的查询,它就会起作用。

(这里有很多代码,所以我不会将其复制到答案中)
http://msdn.microsoft.com/en -us/library/aa390425%28v=vs.85%29.aspx

This MSDN link gives a very detailed example of how to capture events on WMI with COM. The example doesn't actually capture network events - but I believe that if you plug the right query in, it would work.

(lots of code here, so I'm not copying it into the answer)
http://msdn.microsoft.com/en-us/library/aa390425%28v=vs.85%29.aspx

蓝咒 2024-08-25 11:24:15

此 Codeproject 链接提供了详细信息

如何使用 Windows NLM API 获取新网络的通知
连接性

也许有助于解决与此相关的任何挑战。

应用程序通常需要知道机器是否有互联网
连接并据此采取行动。在这个示例中,我们
正在研究 Windows NLM API 在托管代码中的使用,因此
应用程序可以选择响应互联网连接
变化。还有许多其他特定的 NLM API 用于检查域
连接、网络适配器接口等,尚未
本文提到;您可以参考此链接以获取更多信息
细节。可下载的 zip 文件包含源代码。

更多阅读此处

https://www.codeproject.com/Articles/34650/How-to-use-the-Windows-NLM-API-to-get-notified-of

this Codeproject link gives detail on

How to use the Windows NLM API to get notified of new network
connectivity

And maybe helpful to any challenge related to this one.

An application often needs to know if the machine has internet
connectivity and take actions depending on that. In this sample, we
are looking at the usage of the Windows NLM API in managed code so
that an application can choose to respond to internet connectivity
changes. There are many other specific NLM APIs for checking domain
connectivity, network adapter interfaces etc., that haven't been
mentioned in this article; you can refer to this link for further
details. The downloadable zip file has the source code.

more reading here

https://www.codeproject.com/Articles/34650/How-to-use-the-Windows-NLM-API-to-get-notified-of

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文