Re: how to get the status of network when the network is set disable.
Re: how to get the status of network when the network is set disable.
- Subject: Re: how to get the status of network when the network is set disable.
- From: Michael Kaye <email@hidden>
- Date: Wed, 9 Jul 2008 15:07:29 +0100
Try the SCNetworkReachability API...
I borrowed the following from one of Apple's examples:
- (BOOL)isDataSourceAvailable
{
static BOOL checkNetwork = YES;
if (checkNetwork) { // Since checking the reachability of a host
can be expensive, cache the result and perform the reachability check
once.
checkNetwork = NO;
Boolean success;
const char *host_name = "http://localhost:8080";
SCNetworkReachabilityRef reachability =
SCNetworkReachabilityCreateWithName(NULL, host_name);
SCNetworkReachabilityFlags flags;
success = SCNetworkReachabilityGetFlags(reachability, &flags);
_isDataSourceAvailable = success && (flags &
kSCNetworkFlagsReachable) && !(flags &
kSCNetworkFlagsConnectionRequired);
}
return _isDataSourceAvailable;
}
HTHs. Michael.
On 9 Jul 2008, at 13:22, xiaobin wrote:
Hello,
I am writing a program to detect the status of network.
In my program, I need get the status of network when the connection is
set disable. here it is not by connecting the network to get the
status.
which API or method can work for it?
for example, if my lan cable is unpluged or the network is set
disable, it is certainly to know the status of the network is off. so
it is not necessary to connect the network to get the status.
so I want to know When it is clearly to know the status of the network
is on or off, which API or method can get the status.
I have read the example of apple's document for using CFDiagnostics
to check whether the network is connected or not, but I think it is
not for my need. It is by connecting the network to get the status.
Would anyone can give me a help ?
Thanks a lot
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden