Post

Replies

Boosts

Views

Activity

Reply to Choosing interface for multicast UDP
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!
Jun ’25
Reply to Choosing interface for multicast UDP
Should have added here is where I set up my variables: class UDPClient { static let shared = UDPClient() private var connection: NWConnection? private let host = NWEndpoint.Host("239.255.42.99") private let port: NWEndpoint.Port = 54321 private var listener: NWListener? private let receiveQueue = DispatchQueue(label: "UDPReceiveQueue") private var activeConnections: [NWConnection] = []
Jun ’25
Reply to Choosing interface for multicast UDP
For anyone following this I think my buferent and delayed packets were to do with multicast packets going through my router rather than anything in code. I have moved to bonjour and then multiple unicast TCP connections which is working well. Required interface also works in this method.
Replies
Boosts
Views
Activity
Jun ’25
Reply to Choosing interface for multicast UDP
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!
Replies
Boosts
Views
Activity
Jun ’25
Reply to Choosing interface for multicast UDP
Should have added here is where I set up my variables: class UDPClient { static let shared = UDPClient() private var connection: NWConnection? private let host = NWEndpoint.Host("239.255.42.99") private let port: NWEndpoint.Port = 54321 private var listener: NWListener? private let receiveQueue = DispatchQueue(label: "UDPReceiveQueue") private var activeConnections: [NWConnection] = []
Replies
Boosts
Views
Activity
Jun ’25