3
我需要检查仅与IP地址的连接。我试图用Apple Reachability类来实现,使用reachabilityWithAddress选项。而我的问题是我可以在callAddress.sin_addr.s_addr字段中放置任何IP地址,并且statusText总是“可伸缩”。我该如何确切地检查IP地址的连接?iPhone SDK reachabilityWithAddress问题
-(BOOL)reachabilityTest {
struct sockaddr_in callAddress;
callAddress.sin_len = sizeof(callAddress);
callAddress.sin_family = AF_INET;
callAddress.sin_port = htons(24);
callAddress.sin_addr.s_addr = inet_addr("212.83.3.190");
Reachability *hostReach = [[Reachability reachabilityWithAddress:&callAddress] retain];
NetworkStatus netStatus = [hostReach currentReachabilityStatus];
if (netStatus == NotReachable)
{
NSLog(@"NotReachable");
statusField.text = @"NOT reachable";
return NO;
}
if (netStatus == ReachableViaWiFi)
{
NSLog(@"ReachableViaWiFi");
statusField.text = @"reachable";
return YES;
}
[Reachability release];
}
这很难编码,但它工作完美。谢谢你的想法! – MoriQuessir 2010-11-12 14:48:32
下面是一个很棒的connect()例子,它适用于我:http://beej.us/guide/bgnet/output/html/singlepage/bgnet.html#connect – johnnieb 2012-08-30 00:56:46