Thank you for your answer, eskimo.
Following your advice, I created a new clean project to allow us to concentrate on the code. Here is the
entire code of this project :
Code Block | import SwiftUI |
| import Network |
|
| struct ContentView: View { |
| var body: some View { |
| Button(action: { |
| NSLog("Test - Start") |
|
| guard let description = try? NWMulticastGroup(for:[ .hostPort(host: "ff02::114", port: 12345) ]) else { NSLog("ERROR"); return } |
|
| let group = NWConnectionGroup(with: description, using: .udp) |
|
| group.setReceiveHandler(maximumMessageSize: 64 * 1024, rejectOversizedMessages: true) { (message, content, isComplete) in |
| NSLog("Received message from \(String(describing: message.remoteEndpoint))") |
| } |
|
| group.stateUpdateHandler = { (newState) in |
| NSLog("Group entered state \(String(describing: newState))") |
|
| if newState == NWConnectionGroup.State.ready { |
| NSLog("Test - Send Message") |
|
| let groupSendContent = Data("helloAll".utf8) |
| group.send(content: groupSendContent) { error in |
| NSLog("Send complete with error \(String(describing: error))") |
| } |
| } |
| } |
|
| group.start(queue: .main) |
|
| }) {Text("Hello, world!") |
| .padding() |
| } |
| } |
| } |
And here are all the logs I received, when I ran it on the "iPhone SE (2nd generation)"
simulator, :
2020-11-18 11:32:35.054906+0100 test[1178:41190] Test - Start
2020-11-18 11:32:35.188673+0100 test[1178:41412] [] nwlistenersocketinboxcreatesocket setsockopt SONECP_LISTENUUID failed [2: No such file or directory]
2020-11-18 11:32:35.188856+0100 test[1178:41412] [] nwlistenersocketinboxcreatesocket IPV6LEAVE_GROUP ff02::114.12345 failed [49: Can't assign requested address]
2020-11-18 11:32:35.190372+0100 test[1178:41190] Group entered state waiting(POSIXErrorCode: Network is down)
2020-11-18 11:32:35.190541+0100 test[1178:41190] Group entered state ready
2020-11-18 11:32:35.190662+0100 test[1178:41190] Test - Send Message
2020-11-18 11:32:35.206509+0100 test[1178:41412] [] nwprotocolgetquicimageblockinvoke dlopen libquic failed
2020-11-18 11:32:35.218750+0100 test[1178:41412] [connection] nwsocketservicewritesblock_invoke [C1:1] sendmsg(fd 8, 8 bytes) [65: No route to host]
2020-11-18 11:32:35.218930+0100 test[1178:41412] [] nwflowprepareoutputframes Failing the write requests [65: No route to host]
2020-11-18 11:32:35.219823+0100 test[1178:41412] [connection] nwwriterequest_report [C1] Send failed with error "No route to host"
2020-11-18 11:32:35.225903+0100 test[1178:41190] Send complete with error Optional(POSIXErrorCode: No route to host)
I checked with Wireshark, no packets were sent on the 12345 UDP port.
The code was compiled by Xcode 12.2 (12B45b) and the iOS deployment target is 14.2 (iPhone & iPad)