My application connects to the internet to check for updates.
It does so using functions in ras32.dll (RasGetConnectStatus)
If ras32.dll does not exist, I use win inet functions (CInternetSession::OpenURL)
Two problems :
1. If not connected, the wininet functions take a while to time out. I always call it in a thread which i timeout after 5 seconds, but still it's not perfect.
2. RAS functions only work when an internet dialup is present. If you have cable modem / router / lan, RAS will always return "not connected", even if you are.
I read a newsgroup posting from a microsoft guy who suggested also using IsNetworkAlive() and IsDestinationReachable(), but both of those fail for me, regardless of connection state.
I have writtten a class which works well for dialup connection. But in the case of "always on" connections, I have yet to find a good method for detection of internet availability.
Any suggestions guys ?
Jase
Jase
www.slideshowdesktop.com
View your images and photos on your desktop with ease using SlideShow Desktop, the desktop wallpaper manager for Microsoft Windows....
Winsock WSAConnect() sometimes takes five or more seconds to before returning. One solution is to manually close the socket. Thus, as for your question there is no solution.
There must be a way. How do internet browsers know whether or not you are connected to the net ? There absolutley has to be a fool proof way, and it's probably undocumented ...
Jase
Jase
www.slideshowdesktop.com
View your images and photos on your desktop with ease using SlideShow Desktop, the desktop wallpaper manager for Microsoft Windows....
www.slideshowdesktop.com
View your images and photos on your desktop with ease using SlideShow Desktop, the desktop wallpaper manager for Microsoft Windows....
www.slideshowdesktop.com
View your images and photos on your desktop with ease using SlideShow Desktop, the desktop wallpaper manager for Microsoft Windows....
What platform are you testing this on? I tried my function
both at work (Win/XP, VS v6, ethernet (twiested pair))
and at home (Win/XP, VS v6, modem) and every time it
returned the correct answer within a second or less.
My ethernet card (actually it's built into the motherboard)
is an "Intel(R) PRO/100 VE". Maybe that makes a difference..
I've no doubt your function works fine with a dial up modem, but not when you are using a router / lan
Jase
Jase
www.slideshowdesktop.com
View your images and photos on your desktop with ease using SlideShow Desktop, the desktop wallpaper manager for Microsoft Windows....
Do you have an example of a ping() function ?
I don't want to execute ping through the shell if i can help it.
Jase
www.slideshowdesktop.com
View your images and photos on your desktop with ease using SlideShow Desktop, the desktop wallpaper manager for Microsoft Windows....
Originally posted by jase jennings
Do you have an example of a ping() function ?
I don't want to execute ping through the shell if i can help it.
hmm should be something like this, for a shorter condensed version.., I'll pull it outta one of my classes and see if I can shorten it into a small console app in a couple of minutes...
Originally posted by jase jennings
I've no doubt your function works fine with a dial up modem, but not when you are using a router / lan
I tested as follows:
(1) Ethernet cable connected: returned TRUE
(2) Disconnect cable: returnd FALSE
(3) Reconnected cable: returned TRUE
I suppose there must be cases where it fails, but I don't
know what they are or why.
I am attaching a small program that shows how to ping
from your program. Most of the code was posted by
Steve Bryndin at Codeguru. I just modified in small ways.
Note that it does a lot more than just ping a number, e.g.
you can ask it to ping by name, etc. But it works well.
I have a router which my cable modem is connected to. The internet connection is constantly fed to the router. The router then connects two pcs on a home network, thus sharing the cable modem between both pcs.
If i bring the router down, and therefore the network, your original example still returns "connected"
If i bring the cable mode down, but leave the router up, your original code still displays connected.
In either case, the internet is not available.
It may work for you, but be advised that if your ousers are using a similar set up to mine, your code may not work as intended.
Jase
www.slideshowdesktop.com
View your images and photos on your desktop with ease using SlideShow Desktop, the desktop wallpaper manager for Microsoft Windows....
Originally posted by jase jennings
If i bring the router down, and therefore the network, your original example still returns "connected"
If i bring the cable mode down, but leave the router up, your original code still displays connected.
Interesting, thanks. I will try a similar test to check.
Hope the ping sample did the trick.
Originally posted by kochhar
Interesting, thanks. I will try a similar test to check.
Hope the ping sample did the trick.
There is a ton of code out there that uses ping to test connectivity before connection, it's even more useful with COM...Older OS/2 ip stacks were fairly unstable so ping was the option of choice before the socket connection.
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.