0

I am trying to check reachability status for my server using following code:

struct sockaddr_in address;
address.sin_len = sizeof(address);
address.sin_family = AF_INET;
address.sin_port = htons(80);
address.sin_addr.s_addr = inet_addr("172.21.38.120");  

Reachability *hostReachable = [Reachability reachabilityWithAddress:&address];
[hostReachable startNotifier];

and then checking the host status, but it is always giving status as NotReachable. I tried to check whether the server is reachable from terminal using following command:

telnet Hostname port

and Terminal is displaying the status as connected. Is there something that i am doing wrong? Thanks in advance.

Sonal0706
  • 290
  • 3
  • 15

2 Answers2

0

Try changing reachabilityWithAddress to reachabilityWithHostname.

reference : https://github.com/tonymillion/Reachability/issues/9 http://lists.apple.com/archives/macnetworkprog/2009/May/msg00056.html

arundevma
  • 933
  • 7
  • 24
  • I tried reachabilityWithHostName hostReachable = [Reachability reachabilityWithHostName:@"172.21.38.120:3491"]; but then to i am not able to connect to server. – Sonal0706 Oct 31 '12 at 09:02
  • the following piece of code is working for me hostReachable = [Reachability reachabilityWithHostName:@"google.com"]; but how do i connect to a particular ip address – Sonal0706 Oct 31 '12 at 09:06
  • try 172.21.38.120 without port number 3491 – arundevma Oct 31 '12 at 09:27
  • i tried by entering the ip address only,then to its not working. – Sonal0706 Oct 31 '12 at 09:34
0

Since upgrading to XCode 4.6 this has been an issue for me also. I can get it to work without the port - eg 10.1.1.1 works, 10.1.1.1:8000 does not. Previously both worked. Also, XCode and Simulator can cache results/values so if it's not working trying a 'Clean' or resetting your Simulator

arcady bob
  • 1,536
  • 1
  • 10
  • 5