|
-
March 20th, 2003, 11:30 AM
#1
Check network connection availability
Hi, All
I was trying to check the network connection availability using API function IsNetworkAlive, but no matter my computer is or not connected to the network, it always returns true to me, which means the local system is connected to the network. Could anybody ever used this function before help me out?
Thanks
-
March 20th, 2003, 04:17 PM
#2
u can try few tricks, using winsock, try connect to the net:
GetHostByName("http://www.codeguru.com");
return value Zero if cannot connect to host.
note: use winsock reference for APIs.
Bengi
-
March 20th, 2003, 09:34 PM
#3
Thanks, Bengi. I know there are several different ways to check network connection availability.
It is just I saw this IsNetworkAlive function on MSDN and want to tyr it out. But strangely it doesn't work the way it is supposed to be. So I was wondering if somebody has used this before. If they got the same problem, maybe it is a bug of Microsoft platform SDK.
-
March 21st, 2003, 09:42 AM
#4
For the sake of curiosity, I tried the method and worked properly as expected for me without any problems. May be I could help you if you describe what exactly is happening in your case.
-
March 21st, 2003, 02:41 PM
#5
It is just simply several lines of code I wrote to test this function.
char szBuf[1024];
DWORD dwFlag = 0;
if( IsNetworkAlive( &dwFlag ) )
{
switch( dwFlag )
{
case NETWORK_ALIVE_LAN:
MessageBox( NULL, "Computer is connected to LAN", "Connected", MB_OK );
break;
case NETWORK_ALIVE_WAN:
MessageBox( NULL, "Computer is connected to WAN", "Connected", MB_OK );
break;
case NETWORK_ALIVE_AOL:
MessageBox( NULL, "Computer is connected to AOL network", "Connected", MB_OK );
break;
}
}
else
{
sprintf( szBuf, "Can not get network status, error code is %d", GetLastError( ) );
MessageBox( NULL, szBuf, "Not connected", MB_OK );
}
My computer is connected to company LAN, first I ran this code, the function IsNetworkAlive returns true and dwFlag returned is NETWORK_ALIVE_LAN.
then I unplug the LAN cable, ran it again, I am expecting this function will return false to me, but strangely it still returns true and the dwFlag is NETWORK_ALIVE_LAN.
Well, maybe this function is only used to determine what kinds of network connectivity is configured for this computer, isn't used for detecting if network connectivity is available or not.
-
March 23rd, 2003, 10:42 PM
#6
Hi Robin, The API IsNetworkAlive takes the address of the DWORD as a parameter, but the point here is the parameter is [in] rather than [out] as most of the pointers in the parameter list represent generally. Initialize the dwFlag to 1 (which is the value of NETWORK_ALIVE_LAN) and try agiain.
Here we check whether the computer is connected to LAN or WAN or to the AOL n/w and not find out to which type of connection the machine is connected to. As the machine can be connected to more than one type of connection at the same time, it may not be appropriate to get the type of connection from the API.
Done?
-TeeJBee
-
March 24th, 2003, 04:45 PM
#7
Hi, teejbee. Thanks for your reply
I wouldn't think the LPDWORD parameter here is an [in] parameter rather than a [out] paramter. Here is the explanation for this paramter:
LPDWORD lpdwFlags
Provides information on the type of network connection available when the return value is TRUE. The flags can be:
...
As a matter of fact, I did try to initialize the parameter to NETWORK_ALIVE_LAN, but still the same thing happened.
-
March 24th, 2003, 11:13 PM
#8
Hi, The following lines are taken from MSDN library.
Note it may not always be practical for applications to call IsNetworkAlive to determine whether the local system is currently disconnected from a LAN. In this case, IsNetworkAlive can be slow, and it may take too much time for the function to detect that the local system has become disconnected...
This function is only available for TCP/IP connections.
MSDN says the parameter as [in]. May n/w is slow or something strange happening!
Anyway the msdn link is here.
http://msdn.microsoft.com/library/de...tworkalive.asp
-TeeJBee
All The Best
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|