(iphone) 特定 ip/端口的可达性测试? [英] (iphone) reachability test for specific ip/port?

查看:20
本文介绍了(iphone) 特定 ip/端口的可达性测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我查看了来自 Apple 的 Reachability 示例和来自Iphone developer's cook book"的另一个示例

I've looked at Reachability sample from apple and another sample from "Iphone developer's cook book"

这里是测试ip/端口可达性的步骤

Here are steps to test ip/port reachability

  1. 使用给定的 ip/port 构造 sockaddr_in 变量.
  2. 使用地址调用 SCNetworkReachabilityCreateWithAddress
  3. 调用 SCNetworkReachabilityGetFlags 并查看是否设置了 kSCNetworkFlagsReachable.

我发现无论我测试的有效(有效范围)ip/端口是什么,我的代码都说它可以访问,即使当我 ping 或 telnet 测试时它们实际上无法访问.
(我看过其他 SO 帖子,其中对特定 ip 的可达性测试总是成功)ReachabilityreachabilityWithAddress 不起作用

I find that whatever valid(valid-range) ip/port I put to test, my code says it's reachable even though they are not actually reachable when i ping or telnet test.
(I have seen other SO posts where reachability test to specific ip always succeed) Reachability reachabilityWithAddress does not work

是 SCNetworkReachability.. 调用只检查参数的有效性(IP 地址或主机名)?即,他们是否真的向给定地址发送数据包(或连接)以测试可达性?

is SCNetworkReachability.. call only checks the validity of argument(ip address or hostname)? ie, do they actually send a packet(or do connect) to the given address to test reachability?

我可以自己实现带超时的异步连接,但是超时时间不应该被苹果评论者拒绝是一个微妙的问题.(我担心如果时间太长,苹果评论者可能认为我的应用程序没有处理网络可达性)

I can implement the async connect with timeout myself, but it's subtle matter how long the timeout should be not to be rejected by apple reviewers.(I am worried if it takes too long, apple reviewers might think my app is not handling network reachability at all)

谢谢

推荐答案

根据上面的评论回答你的问题,根据 SCNetworkReachability 参考

To answer your question based on the comments above, according to the SCNetworkReachability Reference

远程主机被认为是可达的当一个数据包,由一个应用程序进入网络堆栈,可以离开本地设备.可达性并不能保证数据包实际上是主办方收到.

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.

这将无法检查您的服务器的状态,但只需确保它可以获取数据包.

This will not be able to check the status of your server but just make sure it can get a data packet out.

Apple 希望您的应用程序在出现任何网络相关问题时优雅地失败,第一步是使用 Reachability 检查互联网是否可用.如果 Reachability 失败,您可以假设您将无法使用服务器并立即提醒用户.接下来的步骤是正确处理服务器返回的错误,例如 400 错误请求、404 文件未找到、设置合理的超时时间以及在长时间下载期间不阻塞 UI,同时显示某种状态指示器.

Apple wants for your app to elegantly fail if there are any network related issue, checking to see if internet is available using Reachability is the first step. If Reachability fails you can assume that you wont be able a server and alert the user immediately. The next steps are to properly handle errors returned by your server such as a 400 bad request, 404 file not found, setting a reasonable timeout, and not blocking the UI during long downloads while showing some sort of status indicator.

这篇关于(iphone) 特定 ip/端口的可达性测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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