UDPBroadcastConnection icon indicating copy to clipboard operation
UDPBroadcastConnection copied to clipboard

iOS 14.4.2 / iPhone X – UDP connection failed to send data: No route to host. sendingMessageFailed(code: 65)

Open ctsrc opened this issue 3 years ago • 1 comments

Hi,

I am trying to use the example code, but am getting the following error when I try to invoke sendBroadcast:

"UDP connection failed to send data: No route to host"
sendingMessageFailed(code: 65)
"Closing UDP socket"

In my app I have:

import SwiftUI

// ...

struct ContentView: View {
    // ...
    var conn: UDPBroadcastConnection
    // ...
    init () {
        // ...
        conn = try! UDPBroadcastConnection(
            port: 9012,
            handler: { (ipAddress, port, response) -> Void in
              print("Received from \(ipAddress):\(port):\n\n\(response)")
              },
            errorHandler: { (error) in
              print(error)
            })
    }

    var body: some View {
        // ...
        Button(action: {
            // ...
            do {
                try conn.sendBroadcast("This is a test!")
            } catch {
                print(error)
            }
        }, label: {
            Text("Send")
                .padding([.top, .bottom], 6)
                .padding([.leading, .trailing], 18)
                .background(Color.green)
                .foregroundColor(.white)
        })
        // ...
    }
}

This happens regardless of which port I try to use, and it happens even though I have set a string value for NSLocalNetworkUsageDescription in Info.plist and I say "OK" when I am prompted that my app "would like to find and connect to devices on your local network." along with the message that I set in Info.plist.

I am running the app on an iPhone X with iOS 14.4.2. I am connected to a WiFi network.

ctsrc avatar Apr 04 '21 13:04 ctsrc

I think I found the answer.

https://developer.apple.com/videos/play/wwdc2020/10110/

At about the 6:35 mark in the video above they say that an app needs to have the Multicast Networking Entitlement.

One can apply for this for an app by filling out and submitting the form https://developer.apple.com/contact/request/networking-multicast

Do you know if this applies even for local testing of an App that I am not yet distributing through App Store? And is this the reason for the error I am getting?

ctsrc avatar Apr 04 '21 14:04 ctsrc