3

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.

mentat
  • 2,748
  • 1
  • 21
  • 40

4 Answers4

2

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.

X. Liu
  • 1,070
  • 11
  • 30
Ruddy
  • 1,734
  • 10
  • 11
0

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.

stefaanv
  • 14,072
  • 2
  • 31
  • 53
  • Thanks but I am able to continue transfer from where it was left successfully. But I would like to do that as soon as network / internet is available. So I should detect the network availability in an event based manner. – mentat Jan 20 '10 at 13:47
0

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

FuzzyAmi
  • 7,543
  • 6
  • 45
  • 79
  • And - with this built-in tool you can perform WMI queries without having to run the code around them: (run from command line) wbemtest.exe – FuzzyAmi May 11 '14 at 16:32
0

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

Peter
  • 1,124
  • 14
  • 17