超时连接到服务器

时间:2011-04-14 20:26:18

标签: objective-c cocoa network-programming

如何超时连接尝试?到目前为止,应用程序挂起[iStream open],我想在一段时间后停止连接尝试。

- (void)openConn:(NSString *)urlStr
{  
    NSLog(@"urlstr: %@",urlStr);
    if (![urlStr isEqualToString:@""]) 
    {  

        NSLog(@"open connection");
        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 个答案:

没有答案