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: xiaobin <email@hidden>
- Date: Sun, 13 Jul 2008 01:46:43 +0900
Thank you the quickly advices of Michael and Mike very much.
I test Michael's sample, it works well. But I think the
SCNetworkReachability API is also used to try to connect to the
server, right?
What I want is to get the status of the network without any connection
to the server. Maybe What I said is not so clearly.
Finally, I found the SCDynamicstore API and the following sample
http://www.cocoabuilder.com/archive/message/cocoa/2006/7/21/168076
it seems to give me what i need. I think exactly I need to get the
status of the system configuration.
thank you again
2008/7/10 Mike <email@hidden>:
> 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 (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
>>
> _______________________________________________
>
> 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
>
--
xiaobin
_______________________________________________
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