iPhone EDGE/3G 网络端口范围? 有人知道吗?

发布于 2024-07-14 01:28:28 字数 1050 浏览 7 评论 0原文

我正在尝试在我的 iPhone 应用程序中访问 61616,SCReachability 代码表明我有一个有效的网络,但我在尝试写入 61616 时超时。有谁知道:

A. 如果 iPhone EDGE/3G 网络的端口范围有限或者不允许连接到该端口?

B. 如何明确检查对此端口的访问。 这是我的“网络是否可达”代码(借自Apple的示例),它检查“foo.bar.com”,但不显示如何检查“foo.bar.com:61616”。

任何帮助表示赞赏!

- (BOOL)isDataSourceAvailable{
static BOOL checkNetwork = YES;
BOOL _isDataSourceAvailable = NO;
if (checkNetwork) { // Since checking the reachability of a host can be expensive, cache the result and perform the reachability check once.
    checkNetwork = NO;

    Boolean success;    
    const char *host_name = "foo.bar.com";

    SCNetworkReachabilityRef reachability = SCNetworkReachabilityCreateWithName(NULL, host_name);
    SCNetworkReachabilityFlags flags;
    success = SCNetworkReachabilityGetFlags(reachability, &flags);
    _isDataSourceAvailable = success && (flags & kSCNetworkFlagsReachable) && !(flags & kSCNetworkFlagsConnectionRequired);
    CFRelease(reachability);
}
return _isDataSourceAvailable;

}

I am trying to access 61616 in my iPhone app and the SCReachability code indicates that I have a valid network, but I time out trying to write to 61616. Does anyone know:

A. If the iPhone EDGE/3G network has a limited port range or isn't allowed to connect to this port?

B. How I can check explicitly for access to this port. Here is my "is the network reachable" code (borrowed from Apple's examples), which checks for "foo.bar.com" but doesn't show how to check for "foo.bar.com:61616".

Any help is appreciated!

- (BOOL)isDataSourceAvailable{
static BOOL checkNetwork = YES;
BOOL _isDataSourceAvailable = NO;
if (checkNetwork) { // Since checking the reachability of a host can be expensive, cache the result and perform the reachability check once.
    checkNetwork = NO;

    Boolean success;    
    const char *host_name = "foo.bar.com";

    SCNetworkReachabilityRef reachability = SCNetworkReachabilityCreateWithName(NULL, host_name);
    SCNetworkReachabilityFlags flags;
    success = SCNetworkReachabilityGetFlags(reachability, &flags);
    _isDataSourceAvailable = success && (flags & kSCNetworkFlagsReachable) && !(flags & kSCNetworkFlagsConnectionRequired);
    CFRelease(reachability);
}
return _isDataSourceAvailable;

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

梦里泪两行 2024-07-21 01:28:28

SCNetworkReachability API 仅检查该地址是否可以路由到。 引用文档:

“可达性”反映了数据是否
数据包,由应用程序发送到
网络堆栈,可以离开本地
电脑。 请注意,可达性确实
不保证数据包
主机实际上会收到。

这与 NAT 或端口限制无关。 路由基于地址,而不是端口。 因此,您(通过 SCNetworkReachability API)所能发现的就是您是否可以(理论上)到达机器的接口。 它不会尝试在某个端口上建立连接。

因此,为了查明该服务是否可以访问,您必须尝试并测试自己。 最好是当 SCNetworkReachability API 告诉您可以建立连接时。 只需尝试连接到端口 61616 上的服务器,看看是否能连接或超时。 正确的超时值和处理在这里至关重要。

The SCNetworkReachability API only checks whether the address can be routed to. Quoting the documentation:

"Reachability" reflects whether a data
packet, sent by an application into
the network stack, can leave the local
computer. Note that reachability does
not guarantee that the data packet
will actually be received by the host.

This has nothing to do with NAT or port restrictions. Routing is based on addresses - not on ports. So all you can find out (via SCNetworkReachability API) is whether you could (in theory) reach the machine's interface. It does not try to establish a connection on a certain port.

So in order to find out whether that service is reachable you will have to try and test yourself. Preferably when the SCNetworkReachability API tells you that a connection can be established. Just try to connect to the server on port 61616 and see whether you get a connection or a timeout. Proper timeout values and handling is crucial here.

风吹过旳痕迹 2024-07-21 01:28:28

这不仅因承运商而异,而且因合同而异。 例如,在英国,O2 仅将现收现付客户的互联网访问限制为网址(大概是端口 80 和 443,但我没有检查),但允许用户或多或少免费访问合同。 (我希望它对 iPhone PAYG 客户更加开放。)

我认为这样做的实际结果是,你不能假设可以访问世界各地的高级端口。

我不确定是否有一种简单的方法来检查特定端口是否打开,可能最好的选择是使用“合理的”超时。 当然,导致超时的原因有很多,因此您的错误必须是适当模糊的。

This is something that varies a lot from not just carrier to carrier but from contract to contract. For example, here in the UK O2 restrict internet access only to web addresses (presumably ports 80 and 443 but I didn't check) for pay-as-you-go customers but allow more-or-less free access for people on a contract. (I would hope that it's a little more open for iPhone PAYG customers.)

I think the practical upshot of this is that you can't assume access to high ports everywhere in the world.

I'm not sure that there's a simple way to check that a particular port is open, probably your best option is to use a "reasonable" timeout. Of course, there are a number of reasons you might get the timeout so your error would have to be suitable vague.

絕版丫頭 2024-07-21 01:28:28

如果您的 iPhone 通过 EDGE/Mobile 连接,它可能位于 NAT 网关后面,因此您无法联系它。 至少德国 T-Mobile 就是这样。 iPhone 通过 T-Mobile (172.16.xx) 获取 RFC IP 地址。

我会使用连接到本地 WiFi 网络的 iPhone 进行测试,并且(如果可能的话)通常以 iPhone 联系服务器然后服务器可以与手机通信的方式设计应用程序。

If your iPhone is connected over EDGE/Mobile, it might be behind a NAT gateway thus you being unable to contact it. At least that's the case with T-Mobile Germany. The iPhone gets an RFC IP address by T-Mobile (172.16.x.x).

I would test it with the iPhone connected to your local WiFi net and -- if possible -- generally design the app in a way that the iPhone contacts a server and then the server can communicate with the phone.

暖伴 2024-07-21 01:28:28

您是否正在尝试从外部设备联系您的 iPhone?

这可能行不通。 通常,GPRS/EDGE/UMTS 基础设施会阻止传入连接。 否则,移动用户可能会因他没有请求的不需要的流量而被计费。 (想象一下,在接下来的六周内,有人每秒 ping 您的 iPhone 一次。您将为此付费...)

解决方案是建立从移动设备到远程计算机的连接,然后让远程计算机使用该连接进行流量。

Are you trying to contact your iPhone from an external machine?

That likely does not work. Usually the GPRS/EDGE/UMTS infrastructure blocks incoming connections. Otherwise a mobile subscriber could be billed for unwanted traffic he did not request. (Imagine someone pinging your iPhone once per second for the next six weeks. You would pay for that...)

Solution is to establish a connection from the mobile device to the remote machine and then let the remote machine use that for traffic.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文