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

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

问题描述

我看过苹果的Reachability样本和Iphone开发者的烹饪书中的另一个样本

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

以下是测试ip / port reachability的步骤

Here are steps to test ip/port reachability


  1. 使用给定的ip / port构造sockaddr_in变量。

  2. 使用地址调用SCNetworkReachabilityCreateWithAddress

  3. 调用SCNetworkReachabilityGetFlags并查看是否设置了kSCNetworkFlagsReachable。

我发现无论我测试的有效(有效范围)ip /端口是什么,我的代码都说它可以访问,即使我在ping或telnet测试时实际上无法访问它们。

(我见过其他SO帖子,其中对特定IP的可达性测试总是成功)
可达性reachabilityWithAddress不起作用

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失败,您可以假设您无法使用服务器并立即提醒用户。接下来的步骤是正确处理服务器返回的错误,例如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天全站免登陆