views:

185

answers:

2

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.

A: 

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
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.
Koray Balci
+1  A: 

You might want to check out the System Event Notification Server (SENS) API http://msdn.microsoft.com/en-us/library/cc185680(VS.85).aspx

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.

Ruddy
Looks like it is only for mobile platforms. Gotta look more.
Koray Balci
Edited answer to include suggestion on using WMI
Ruddy
Related: http://stackoverflow.com/questions/1085045/check-whether-internet-connection-is-available-with-c
Ruddy