Thank you. I have got it working with NWMulticastGroup but, interfacing aside, I have an issue I had back when I was using NWConnection as well. After a period of inactivity (5 minutes) the receiver is buffering all the messages it receives within a second and then releasing them all. My server is sending out 20 messages per second. Wireshark confirms that these are leaving as a steady stream, but the receiving side (IOS) becomes jittery and updates every second. If I close the group and reopen the connection it's solved, but then I cant send messages back to the MacOS app without also closing and reopening that connection. Here is the start of my listener on iOS:
func openConnection() {
let host = NWEndpoint.Host(multicastAddress)
let multicastEndpoint = NWEndpoint.hostPort(host: host, port: port)
do {
activity = ProcessInfo.processInfo.beginActivity(options: [.background, .latencyCritical], reason: "Multicast receiving")
let group = try NWMulticastGroup(for: [multicastEndpoint])
self.multicastGroup = group
let parameters = NWParameters.udp
parameters.allowLocalEndpointReuse = true
parameters.includePeerToPeer = true
parameters.serviceClass = .responsiveData
// Bind to 0.0.0.0:54321
let localHost = NWEndpoint.Host.ipv4(.any)
let localPort = port
parameters.requiredLocalEndpoint = .hostPort(host: localHost, port: localPort)
// Then create the group
let connectionGroup = NWConnectionGroup(with: group, using: parameters)
self.connectionGroup = connectionGroup
connectionGroup.setReceiveHandler(maximumMessageSize: 65536, rejectOversizedMessages: true) { data, content, isComplete in
guard let data = content, data.count >= 4 else {
print("No or insufficient multicast data")
return
}
As you can see I have tried parameters.serviceClass = .responsiveData and also activity = ProcessInfo.processInfo.beginActivity(options: [.background, .latencyCritical], reason: "Multicast receiving")
thanks in advance!