Reachability reachabilityWithAddress does not work
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 rea开发者_如何学编程chabilityWithAddress:&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.
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.
精彩评论