Timeout connecting to server
how can I timeout a connection attempt? By now the application hangs on [iStream open]
and I want to stop the connection attempt after a certain time.
- (void)openConn:(NSString *)urlStr
{
NSLog(@"urlstr: %@",urlStr);
if (![urlStr isEqualToString:@""])
{
NSLog(@"open con开发者_开发技巧nection");
NSHost *host= [NSHost hostWithAddress:urlStr];
[NSStream getStreamsToHost:host port:47141 inputStream:&iStream outputStream:&oStream];
[iStream retain];
[oStream retain];
[iStream setDelegate:self];
[oStream setDelegate:self];
[iStream scheduleInRunLoop:[NSRunLoop currentRunLoop]
forMode:NSDefaultRunLoopMode];
[oStream scheduleInRunLoop:[NSRunLoop currentRunLoop]
forMode:NSDefaultRunLoopMode];
[iStream open];
[oStream open];
[self connGame];
}
}
精彩评论