ios - POSIX网络没有激活蜂窝 radio ?

标签 ios iphone sockets networking

我正在阅读 Networking Programming Topics:Using Sockets and Socket Streams,有一段告诉我们不要在 iOS 上使用 POSIX 套接字 API,它说:

In iOS, POSIX networking is discouraged because it does not activate the cellular radio or on-demand VPN. Thus, as a general rule, you should separate the networking code from any common data processing functionality and rewrite the networking code using higher-level APIs.

如文档所述,如果我使用 POSIX 套接字来完成我的网络工作,那么它不会激活蜂窝 radio 。我想过如果我的设备没有连接WIFI,我的应用程序将无法访问互联网,但我通过编写下面的代码来否定它。

在这个例子中,我只使用 POSIX socket api 并连接到谷歌的 DNS 服务器,当我的 iPhone 连接到蜂窝 radio (没有 WIFI)时它成功了。

int clientSocket = socket(AF_INET, SOCK_STREAM, 0) ;
struct sockaddr_in server_addr ;
bzero(&server_addr, sizeof(server_addr)) ;
server_addr.sin_port = htons(53) ;
server_addr.sin_addr.s_addr = inet_addr("8.8.8.8") ;
server_addr.sin_family = AF_INET ;

int i = connect(clientSocket, (const struct sockaddr *)&server_addr, sizeof(server_addr)) ;
if (i >= 0) {
    NSLog(@"connected") ;
}
close(clientSocket) ;

现在我的问题是“激活蜂窝 radio ”是什么意思以及系统何时会停用蜂窝 radio

提前致谢。

最佳答案

关于ios - POSIX网络没有激活蜂窝 radio ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25032809/

相关文章:

ios - UIView 阴影,cornerradius 不工作

iphone - 如何将 "filters"应用于 AVCaptureVideoPreviewLayer

ios - 在 UITableView 中删除行但不使用删除按钮

linux - 哪种双栈服务器方法更好?

java - SSLSockets 和密码规范问题

ios - 二元运算符 '<' 不能。应用于两个 'Any?' 操作数

iphone - 使用谓词过滤数组中对象的属性

iOS App 兼容所有设备版本

iphone - 将 .xib 中的对象连接到现有的 IBAction

java - 套接字编程、多线程编程。错误 : IOException: java.net.ConnectException:连接超时:连接