捕获网络状态变化事件
我试图在互联网连接丢失后重新建立时获取事件。这是我正在开发的数据传输软件。如果我在数据传输过程中失去网络,我希望在网络恢复时收到通知并自动继续传输。
我当然可以创建一个单独的线程并使用计时器偶尔检查一次网络,但也许有更好的选择。
我主要使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可能想查看系统事件通知服务器 (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.
我不知道您使用哪种协议以及您是否可以控制目的地,但在这种情况下,目的地可以轮询重试。目的地最清楚它所接收到的内容,因此它可以给出接收到的字节数作为重传的偏移量。
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.
此 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
此 Codeproject 链接提供了详细信息
也许有助于解决与此相关的任何挑战。
更多阅读此处
https://www.codeproject.com/Articles/34650/How-to-use-the-Windows-NLM-API-to-get-notified-of
this Codeproject link gives detail on
And maybe helpful to any challenge related to this one.
more reading here
https://www.codeproject.com/Articles/34650/How-to-use-the-Windows-NLM-API-to-get-notified-of