-1

Possible Duplicate:
iPhone SDK reachabilityWithAddress issue

I am trying to determine if the iphone can connect to a particular IP address (Simple ping) using following code:

struct sockaddr_in server_address;   
server_address.sin_len = sizeof(server_address);
server_address.sin_family = AF_INET;
server_address.sin_port = htons(8888);
server_address.sin_addr.s_addr = inet_addr("192.168.105.44"); // ip address of a server on LAN
Reachability *r = [[Reachability reachabilityWithAddress:&server_address ] retain];
NetworkStatus internetStatus = [r currentReachabilityStatus];

But it always says that the status is 'Reachable' regarless of what I give in the IP address. Am I doing anything wrong? Why won't this work? Thanks in advance.

Community
  • 1
  • 1
Ashutosh Dubey
  • 385
  • 1
  • 4
  • 14
  • I cant create a new connection since i must be already connected for the same ip using AsyncSocket. I just want to check on some event whether i am connected or not. onSocketDidDisconnect delegate method of is not called when we plug out the LAN cable from server. – Ashutosh Dubey Aug 08 '12 at 11:12

1 Answers1

1

Same behavior

 + (Reachability*) reachabilityWithHostName: (NSString*) hostName;

Reachability will always return TRUE, doesn't matter if your HTTP return code will be 200 or 404. If you can not use the solution the link posted by Prince suggests, you can

  1. Check your internet reachability
  2. Fire a timer based HTTPRequest and check the return code

or check NetReachability.

Don't know if it helps you as it uses the same framework and I had no time to test it myself.

lindinax
  • 282
  • 2
  • 6