可达性reachabilityWithAddress不起作用 [英] Reachability reachabilityWithAddress does not work

查看:53
本文介绍了可达性reachabilityWithAddress不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用以下代码确定iPhone是否可以连接到我的IP地址

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];

但是它总是说状态为可达到",与我在IP地址中给出的无关.我做错什么了吗?为什么不起作用?感谢您的见识.

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.

推荐答案

签出此答案( https://stackoverflow.com/a/5875059/1067154 )

SCNetworkReachability参考

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

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.

这篇关于可达性reachabilityWithAddress不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆