2

Possible Duplicate:
Ping with iPhone SDK

I am creating a application. Where before sending request to server i need to long server. How can i do that?

Community
  • 1
  • 1

3 Answers3

4

You should check the reachability utility that Apple made:

Reachability on developer.apple.com

I think that will do what you want to do.

EDIT

use it like this:

+(BOOL)canConnect {
    Reachability *r = [Reachability reachabilityWithHostName:@"www.example.com"];
    NetworkStatus internetStatus = [r currentReachabilityStatus];
    return ((internetStatus == ReachableViaWiFi) || (internetStatus == ReachableViaWWAN));
}

It will check if you can connect to the internet, and if you can connect to the server with the given adress/ip.

Manuel
  • 10,153
  • 5
  • 41
  • 60
  • 2
    I tried that one also . But i was just able to check weather my device is connected to network or not. But my requirement is that i need to ping server. – akrant_iOSDeveloper Apr 10 '12 at 12:06
  • I tried this when I was connected to a WIFI with no internet access. But currentReachabilityStatus is always ReachableViaWifi. Even if the reachability instance is created like [Reachability reachabilityWithHostname:@"Dummy"] – Siamaster Nov 11 '16 at 14:54
  • Incorrect answer. – tonso Oct 12 '18 at 23:39
0

Check the Reachability example in apple. That provides step by step to check if ip is connectable.

Satish
  • 170
  • 3
  • 12
0

You may use a lot of variants starting from NSURLRequest and so on

Horhe Garcia
  • 882
  • 1
  • 13
  • 28