问题描述
我正在尝试检查服务器是联机还是脱机:我遇到的问题是服务器连接时具有端口
I am trying to check whether a server is online or offline: I face the problem that it has a port when connecting to it
此刻我的代码:
struct sockaddr_in address;
address.sin_len = sizeof(address);
address.sin_family = AF_INET;
address.sin_port = htons(25667);
address.sin_addr.s_addr = inet_addr("fr7.mooshroom.net");
Reachability *reachability = [Reachability reachabilityWithAddress:&address];
请让我知道我做错了什么.并且请不要将我链接到其他问题,我已经搜索过了,没有一个人有我想要的东西.
Please let me know what im doing wrong. And please dont link me to other questions, I have searched and none of them have what I'm looking for.
推荐答案
我已经修复了它,我需要在这行中输入:const char *serverIPChar = [serverIP cStringUsingEncoding:NSASCIIStringEncoding];
并将inet_addr
内的"fr7.mooshroom.net"替换为serverIPChar
.还是谢谢你
I have fixed it now, i needed to put the line:const char *serverIPChar = [serverIP cStringUsingEncoding:NSASCIIStringEncoding];
and replace the "fr7.mooshroom.net" inside the inet_addr
to serverIPChar
. Thanks anyway
这篇关于地址可达性-服务器和端口-iOS 5的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!