我正在尝试使用Reachability ping服务器。以下是我正在尝试的代码片段,但我得到了null Reachability对象,我解决了将AF_INET6更改为AF_INET。 现在,这段代码片段正在检查连接性。 但我想检查我正在ping的服务器是否有效。
#import "Reachability.h"
#import <netinet/in.h>
#import <netinet6/in6.h>
#import <sys/socket.h>
#import <arpa/inet.h>
- (IBAction)checkConnection:(id)sender {
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("10.29.6.48");
Reachability *reachibility = [Reachability reachabilityWithAddress:&callAddress];
NetworkStatus netStatus = [reachibility currentReachabilityStatus];
NSLog(@"%@",netStatus);
}
如何ping服务器?