简体   繁体   English

为什么在使用dispatch_async()方法时AsyncSocket无法连接到主机?

[英]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. 当使用dispatch_async方法使用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. 我使用此代码进行连接,但没有成功,事件- (void)onSocket:(AsyncSocket *)sock willDisconnectWithError:(NSError *)err没有被调用。 Anybody knows why? 有人知道为什么吗? thanks. 谢谢。

ps forgive my English. ps原谅我的英语。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么在requestAccessToEntity中使用performSegueWithIdentifier时使用dispatch_async:completion? - Why use dispatch_async when using performSegueWithIdentifier in requestAccessToEntity:completion? 在方法内部或调用该方法时使用dispatch_async() - Use dispatch_async() inside a method or when calling that method 将块与dispatch_async一起使用 - Using blocks with dispatch_async 使用dispatch_async造成混乱 - Confusion using dispatch_async iOS:当应用程序状态为UIApplicationStateBackground时,为什么dispatch_async不会运行到主线程? - iOS: Why won't dispatch_async to main thread run when application state is UIApplicationStateBackground? 与不使用dispatch_async相比,为什么使用dispatch_async是如此之慢? - Why using dispatch_async is so slow compared to not using it at all? 在Swift iOS中无法使用dispatch_async方法更新UILabel - Unable to update UILabel using dispatch_async method in swift iOS performSelector:使用 dispatch_async 和 global_queue 时无法正常工作 - performSelector: didn't work properly when using dispatch_async and global_queue dispatch_async实际何时分配? - When does dispatch_async actually dispatch? 为什么使用dispatch_async对性能有很大帮助? - Why is using dispatch_async helping with performance so much?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM