iOS - GCDAsyncUdpSocket投掷错误域= NSPOSIXErrorDomain代码= 65“无主机路由”

时间:2016-11-24 13:07:07

标签: ios gcdasyncudpsocket

有时我收到此错误

  

错误域= NSPOSIXErrorDomain代码= 65“无主机路由”   UserInfo = {NSLocalizedDescription =无主机路由,   NSLocalizedFailureReason = send()函数中的错误。}

在某些路由器中打开udp套接字时。我不知道是什么原因引起的。

这是我打开udp套接字的代码:

- (void)openSocket
{
    if(_asyncUdpSocket == nil)
    {
        _asyncUdpSocket = [[GCDAsyncUdpSocket alloc] initWithDelegate:self delegateQueue:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)];
    }

    if(![_asyncUdpSocket isClosed])
    {
        return;
    }

    NSError *error;

    if (![_asyncUdpSocket enableBroadcast:YES error:&error])
    {
        NSLog(@"AsyncUdp: enable broadcast failed error: %@", error);
    }

    if (![_asyncUdpSocket bindToPort:_port error:&error])
    {
        NSLog(@"AsyncUdp: bind to port %li failed error: %@", (unsigned long)_port, error);
    }

    if (![_asyncUdpSocket joinMulticastGroup:_address error:&error])
    {
        NSLog(@"AsyncUdp: join multicast group %@ failed error: %@", _address, error);
    }

    if(![_asyncUdpSocket beginReceiving:&error])
    {
        NSLog(@"AsynUdp: begin receiving error: %@", error);
    }

    if(error != nil)
    {
        NSLog(@"Udp failed to open!");

        [_delegate onUdpSocketDidOpenfailed];
    }

    else
    {
        NSLog(@"UdpSocket - opend udp socket successful!");

        [_delegate onUdpSocketDidOpen];
    }
}

请注意,这在iPhone 7中经常发生

1 个答案:

答案 0 :(得分:0)

将 Xcode 更新到版本 12.5 后,我在运行 DLNA App 项目时遇到了同样的问题。我通过将 Xcode 降级到 12.4 版来修复它。