The SCF documentation specifically says SC routines cannot be used to test *remote* reachability and should only be used to test whether a packet can *leave* the host. If this is all you need, then Michael's example will work. If you need to test remote reachability, you will need to devise some other method.

Mike

Michael Kaye wrote:
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 (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/michaelkaye%40mac.com

This email sent to [EMAIL PROTECTED]

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/junklists%40michael-amorose.com

This email sent to [EMAIL PROTECTED]

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to