Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS - Multicast networking failed : "Can't assign requested address"

I followed the Apple instructions carefully.

    guard let multicast = try? NWMulticastGroup(for:[ .hostPort(host: "224.0.0.251", port: 5353) ]) else { NSLog("ERROR"); return }
    
    let group = NWConnectionGroup(with: multicast, using: .udp)
    group.setReceiveHandler(maximumMessageSize: 16384, rejectOversizedMessages: true) { (message, content, isComplete) in
        NSLog("Received message from \(String(describing: message.remoteEndpoint))")
    }
    group.start(queue: .main)

However when I run this code I get the following error :

[49: Can't assign requested address]

The platform is iOS 14.2 and the problem persists if I run the program on a real device or through the simulator.

I have the com.apple.developer.networking.multicast entitlement and it is correctly configured.

I tried with various IP addresses (IPV4 and IPV6) and various ports, without any results.

like image 726
Denis Avatar asked Nov 29 '25 06:11

Denis


1 Answers

I have contacted Apple DTS (Developer Technical Support) with the exact same question as you.

After investigating with the technician, we were able to conclude that even though we got this error message along with two others, the multicast still worked. More specifically, these are the three exact errors that we both got:

MulticastTest[49964:2029188] [] nw_listener_socket_inbox_create_socket setsockopt SO_NECP_LISTENUUID failed [2: No such file or directory]
MulticastTest[49964:2029188] [] nw_listener_socket_inbox_create_socket IP_DROP_MEMBERSHIP 224.0.0.1:28650 failed [49: Can't assign requested address]
     [NWConnectionGroup][state] group entered state waiting(POSIXErrorCode: Network is down)

For me, the reason why my original project was not working is due to the fact that the .entitlement file was never included in the build settings in XCode even though everything else was configured correctly. This wasn't ever mentioned in the instructions on how to properly set up the multicast entitlement found here: https://developer.apple.com/forums/thread/663271.

You can find both mine and the technician's working udp multicast projects here: https://github.com/richardwei6/Swift-Native-UDP-Multicast-Testing

This does answer your question but may not entirely fix your issue. However, it is worth a look.

Hope this helped!

like image 135
Richard Wei Avatar answered Dec 01 '25 18:12

Richard Wei