Monday, August 26, 2013

Ping a particular host using objective c

Ping a host and check for reachability

So heres the code (Make sure you add the SystemConfiguration Framework in your project before you begin with this)



- (BOOL)pinghosttoCheckNetworkStatus
{
    bool success = false;
    const char *host_name = [@"itunesconnect.apple.com"
                             cStringUsingEncoding:NSASCIIStringEncoding];
    
    SCNetworkReachabilityRef reachability = SCNetworkReachabilityCreateWithName(NULL,host_name);
    SCNetworkReachabilityFlags flags;
    success = SCNetworkReachabilityGetFlags(reachability, &flags);
    bool isAvailable = success && (flags & kSCNetworkFlagsReachable) &&
    !(flags & kSCNetworkFlagsConnectionRequired);
    if (isAvailable)
    {
        return YES;
    }else{
        return NO;
    }
}



Happy iCoding and have a great day.

Join Us on Facebook