我正在使用GBPing来ping几个调用方法的IP。 问题是GBPing通过委托方法给出结果,我不知道如何监视来自另一个线程的委托结果。
示例代码,用于ping N个主机的循环。
for(int i=1; i< pow(2,(32-netmask)) -1; i++){
ph[i] = [[PingHelper alloc] init];
//compose IPv4
NSString *finalAddr = [IPHelper composeIPv4:addrs[0] netmask:netmask host:i];
[ph[i] ping:finalAddr semaphore:NULL];
}
PingHelper电话。
self->ping = [[GBPing alloc] init];
self->ping.host = host;
self->ping.delegate = self;
self->ping.timeout = 1.0;
self->ping.pingPeriod = 0.9;
[self->ping setupWithBlock:^(BOOL success, NSError *error) { //necessary to resolve hostname
if (success) {
//start pinging
[self->ping startPinging];
}
else {
NSLog(@"failed to start");
}
}];
//while(!finished);
return result;
谢谢, 奥斯卡