gpt4 book ai didi

iphone - 可达性reachabilityWithAddress不起作用

转载 作者:行者123 更新时间:2023-12-03 19:02:09 25 4
gpt4 key购买 nike

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

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 地址中提供什么,它总是显示状态为“可访问”。我做错了什么吗?为什么这不起作用?感谢您的见解。

最佳答案

查看此答案 ( 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.

关于iphone - 可达性reachabilityWithAddress不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5001955/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com