Re: Detecting Internet
Re: Detecting Internet
- Subject: Re: Detecting Internet
- From: "Adam R. Maxwell" <email@hidden>
- Date: Fri, 14 Jul 2006 06:33:19 -0700
On Jul 14, 2006, at 02:12, Gerriet M. Denkmann wrote:
When my app runs on a computer which connects to the internet via
the internal modem then the SCNetworkReachability... functions work
very well.
If no internet is available Safari shows a page "You are not
connected to the..." immediately, and [NSHost hostWithName: ]
returns nil at once.
But when the computer accesses the internet through the Build-in
Ethernet then the reachability functions don't help.
And in this case Safari takes 2 minutes to detect the absence of an
internet connection; NSHost takes 1 minute to return nil.
What do you mean when you say they don't help? I'm using the
following code (gleaned from the list archives) in a couple of
applications, and it works equally well with modem, Ethernet, and
Airport.
BOOL result = NO;
SCNetworkConnectionFlags flags;
const char *hostName = "myhost.mydomain.com";
if( SCNetworkCheckReachabilityByName(hostName, &flags) ){
result = !(flags & kSCNetworkFlagsConnectionRequired) &&
(flags & kSCNetworkFlagsReachable);
}
-- adam
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden