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....
ran into this problem of having to detect the presence of an internet connection, found this thread and decided to post my VERY unsatisfying, but working, 'solution'. Especially the part where it needs a batch file is extremely annoying.
Moreover, as discussed in this thread, this 'solution' obviously doesn't work from behind routers that disabled pinging.
cheers,
Dennis
Code:
#include <stdio.h>
#include <string.h>
#include <process.h>
int main(int argc, char* argv[])
{
FILE *f1;
int check;
char fbuf[150];
// try to ping 66.102.11.104 (www.google.nl), just ONCE, waiting for MAX 500 msec
// batch file needed because ping doesn't take "> testIC.bat" for an argument
check = spawnl( P_WAIT, "c:\\windows\\testIC.bat", "testIC.bat", "500", "1",
"66.102.11.104", "c:\\windows\\testIC.tmp", NULL );
if( check == -1 )
// error from spawnl
return -1;
f1 = fopen( "c:\\windows\\testIC.tmp", "rb" );
if( !f1 )
// error opening file
return -1;
// read the first 149 bytes from testIC.tmp
fread( fbuf, 149, 1, f1 );
fbuf[149] = NULL;
fclose( f1 );
if( strstr( fbuf, "Reply from" ) != NULL )
// reply received, internet connection viable
return 1;
// no reply received, assume internet connection lost
return 0;
}
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.
* 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.