We're trying to re-implement our proprietary SSDP implementation (currently using CocoaAsyncSocket) using Apple's Network framework for iOS 14, based on Apple's example on how to use multicast networking in an App.
This is the code of our spike:
While we see plenty of HTTP/1.1 200 OK responses to our M-SEARCH request in Wireshark, iOS 14 Beta 5 is hardly ever calling NWConnectionGroup's handler (line 6) for any received messages (sent from members of the group to the local endpoint).
Do we need to use different NWParameters settings to make sure this handler is called for every response?
Or is this a bug in iOS 14 Beta 5?
Reported as FB8461681.
This is the code of our spike:
Code Block swift guard let multicastGroup = try? NWMulticastGroup(for: [ .hostPort(host: "239.255.255.250", port: 1900) ]) else { fatalError("Failed to create multicast group") } let connectionGroup = NWConnectionGroup(with: multicastGroup, using: .udp) connectionGroup.setReceiveHandler(maximumMessageSize: 16384, rejectOversizedMessages: true) { message, content, isComplete in print("Received message from \(String(describing: message.remoteEndpoint))") if let content = content, let message = String(data: content, encoding: .utf8) { print("Message: \(message)") } } connectionGroup.stateUpdateHandler = { newState in print("Group entered state \(String(describing: newState))") } connectionGroup.start(queue: .main) let searchString = "M-SEARCH * HTTP/1.1\r\n" + "HOST: 239.255.255.250:1900\r\n" + "MAN: \"ssdp:discover\"\r\n" + "ST: ssdp:all\r\n" + "MX: 1\r\n\r\n" let groupSendContent = Data(searchString.utf8) Timer.scheduledTimer(withTimeInterval: 5, repeats: true) { _ in connectionGroup.send(content: groupSendContent) { error in print("Send complete with error \(String(describing: error))") } }
While we see plenty of HTTP/1.1 200 OK responses to our M-SEARCH request in Wireshark, iOS 14 Beta 5 is hardly ever calling NWConnectionGroup's handler (line 6) for any received messages (sent from members of the group to the local endpoint).
Do we need to use different NWParameters settings to make sure this handler is called for every response?
Or is this a bug in iOS 14 Beta 5?
Reported as FB8461681.