Reachability reachabilityWithAddress does not work

社会主义新天地 提交于 2019-12-10 15:08:18

问题


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.


回答1:


checkout this answer (https://stackoverflow.com/a/5875059/1067154)

SCNetworkReachability Reference

The SCNetworkReachability programming interface allows an application to determine the status of a system's current network configuration and the reachability of a target host.

A remote host is considered reachable when a data packet, sent by an application into the network stack, can leave the local device. Reachability does not guarantee that the data packet will actually be received by the host.



来源:https://stackoverflow.com/questions/5001955/reachability-reachabilitywithaddress-does-not-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!