Click to See Complete Forum and Search --> : How to detect if you are connected to internet?


kfaday
June 21st, 2004, 09:15 AM
Hi,
i'm creating a jabber client (a chat tool, like icq or msn). In the app, i send info to a server, and i receive from it. I use MFC CSocket.
Is there any api function that checks if you are connected to internet?

thanks!!!

Marc G
June 21st, 2004, 09:39 AM
If you would have searched the forums first, you would have found the following function: InternetGetConnectedState ;)

kfaday
June 21st, 2004, 10:08 AM
i looked it up in msdn (link) (http://msdn.microsoft.com/library/?url=/library/en-us/wininet/wininet/internetgetconnectedstate.asp) , and i don't understand the following:

lpdwFlags
[out] Pointer to a variable that receives the connection description. This parameter can be one or more of the following values.
Value Meaning
INTERNET_CONNECTION_CONFIGURED Local system has a valid connection to the Internet, but it might or might not be currently connected.
INTERNET_CONNECTION_LAN Local system uses a local area network to connect to the Internet.
INTERNET_CONNECTION_MODEM Local system uses a modem to connect to the Internet.
INTERNET_CONNECTION_MODEM_BUSY No longer used.
INTERNET_CONNECTION_OFFLINE Local system is in offline mode.
INTERNET_CONNECTION_PROXY Local system uses a proxy server to connect to the Internet.
INTERNET_RAS_INSTALLED Local system has RAS installed.


the following code always returns online.. any ideas?

unsigned long *a;
a=(unsigned long *)malloc(sizeof(unsigned long));
if (TRUE==InternetGetConnectedState(a,0))
AfxMessageBox("online");
else
AfxMessageBox("offline");

Mathew Joy
June 21st, 2004, 11:31 PM
Broadly speaking, there is no fool proof solution to your question. There was a long running threadDetecting an internet connection (http://www.codeguru.com/forum/showthread.php?s=&threadid=257474) , with lots of solutions posted. You can choose one that is appropriate for you.

kfaday
June 22nd, 2004, 07:31 AM
thanks!