简体   繁体   中英

Why AsyncSocket can't connect to host when using dispatch_async() method?

I'm a little confused when using dispatch_async method to use AsyncSocket. Here's my code

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
    _socket = [[AsyncSocket alloc] initWithDelegate:self];
    [_socket connectToHost:@"192.168.1.122" onPort:9501 error:nil];
    [self sendCurrentLocation];
});

I use this code to connect, but It didn't work, event - (void)onSocket:(AsyncSocket *)sock willDisconnectWithError:(NSError *)err isn't invoked. Anybody knows why? thanks.

ps forgive my English.

AsyncSocket数据传输是异步的,它将数据放置在队列中,使用线程发送,因此我们不需要再次异步进行。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM