5

I am trying to determine if the iphone can connect to my IP address 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("1.2.3.4");
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 for your insight.

4

1 回答 1

0

签出这个答案(https://stackoverflow.com/a/5875059/1067154

SCNetworkReachability 参考

SCNetworkReachability 编程接口允许应用程序确定系统当前网络配置的状态和目标主机的可达性。

当应用程序发送到网络堆栈的数据包可以离开本地设备时,远程主机被认为是可达的。可达性并不能保证数据包会真正被主机接收。

于 2013-10-11T04:30:52.093 回答