我在我的应用程序中使用以下代码,
但是当我设置192.168.0.1(inhexadecimal form)
之类的 IP 地址代替INADDR_ANY/0x7f000001(127.0.0.1)时出现错误。
BAction)createSocket:(id)sender {
CFSocketContext CTX = {0, "this is server", NULL, NULL, NULL};
tcpServer = CFSocketCreate(NULL,0, 0, 0,kCFSocketAcceptCallBack, 0, &CTX);
if (tcpServer == NULL)
NSLog(@"server isn't created");
else
NSLog(@"sever is successfully created");
struct sockaddr_in addr;
memset(&addr, 0, sizeof(addr));
addr.sin_len = sizeof(addr);
addr.sin_family = AF_INET;
addr.sin_port = htons(2048);
addr.sin_addr.s_addr = htonl(0x7f000001);
NSData *address = [ NSData dataWithBytes: &addr length: sizeof(addr) ];
if (CFSocketSetAddress(tcpServer, (__bridge CFDataRef) address) != kCFSocketSuccess) {
NSLog(@"socket address not set");
}
else
{
NSLog(@"socket address is successfully added");
}
我可以添加其他 IP 地址或使用其他 IP 的任何限制吗?如果可以比怎么办?
我想使用其他 ip,因为我正在使用三个 iphone 相互连接。