开发者

Timeout connecting to server

开发者 https://www.devze.com 2023-02-25 10:05 出处:网络
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.

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

精彩评论

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