Rectangle 27 32

I had this same problem, and ended up writing a simple wrapper around SimplePing to achieve this, wrote a blog about it and there's some code on github, hopefully will help someone here:

Upvote for a solution that actually answers the question (vs all this useless Reachability stuff which people seem to like but which is totally not addressing the question asked!). Thank you!

Yes, this is the actual answer.

iphone - How to write a simple Ping method in Cocoa/Objective-C - Stac...

iphone objective-c cocoa cocoa-touch networking
Rectangle 27 1

Check internet connection in bash (you could write a small app for this) or try to ping some site and write the result somewhere.

Thanks, Can you tell me a command in linux that could do this. and how to get the output of the command and set it to a property

deployment - ant check internet connection - Stack Overflow

deployment ant build connection
Rectangle 27 1

Check internet connection in bash (you could write a small app for this) or try to ping some site and write the result somewhere.

Thanks, Can you tell me a command in linux that could do this. and how to get the output of the command and set it to a property

deployment - ant check internet connection - Stack Overflow

deployment ant build connection
Rectangle 27 0

The answer Gene Myers posted works using "SCNetworkReachabilityCreateWithName" for me - but only in the simulator. On my device (iPod w/OS 2.2.1) it always returns "Host is reachable" even for nonsense addresses like "zzz".

- (IBAction) TestReachability:(id)sender
{
    bool success = false;
    const char *host_name = [ipAddressText.textcStringUsingEncoding:NSASCIIStringEncoding];
    NSString *imageConnectionSuccess = @"Connected.png";
    NSString *imageConnectionFailed = @"NotConnected.png";

    SCNetworkReachabilityRef reachability = SCNetworkReachabilityCreateWithName(NULL,
                                                                                host_name);
    SCNetworkReachabilityFlags flags;
    success = SCNetworkReachabilityGetFlags(reachability, &flags);
    bool isAvailable = success && (flags & kSCNetworkFlagsReachable) && 
        !(flags & kSCNetworkFlagsConnectionRequired);
    if (isAvailable)
    {
        NSLog([NSString stringWithFormat: @"'%s' is reachable, flags: %x", host_name, flags]);
        [imageView setImage: [UIImage imageNamed:imageConnectionSuccess]]; 
    }
    else
    {
        NSLog([NSString stringWithFormat: @"'%s' is not reachable", host_name]);
        [imageView setImage: [UIImage imageNamed:imageConnectionFailed]]; 
    }
}

iphone - How to write a simple Ping method in Cocoa/Objective-C - Stac...

iphone objective-c cocoa cocoa-touch networking