开发者

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];


    }  


}  
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜