Hi all. Title says it all really. I have an app on MacOS that sends multicast UDP to multiple iOS devices. It shows realtime bar numbers of music played back by a playback software. It was all working until I tried a direct ethernet connection between Mac and phone - a scenario that would be quite common in the theatre world where machines dont have internet connection and people dont rely on wifi. How can I choose which interface my app sends the data through? Here is my connection function:
func openConnection() { let params = NWParameters.udp params.allowLocalEndpointReuse = true params.includePeerToPeer = true let endpoint = NWEndpoint.hostPort(host: host, port: port) let conn = NWConnection(to: endpoint, using: params) self.connection = conn conn.stateUpdateHandler = { state in switch state { case .ready: print("Multicast connection ready to \(self.host)") UDPClient.console.log("Multicast connection ready to \(self.host)") case .failed(let error): print("Multicast connection failed: \(error)") default: break } } let udpQueue = DispatchQueue(label: "UDPClientQueue") conn.start(queue: udpQueue) }
Thanks for any help in advance!
With a normal UDP connection you can force the flow over a specific interface by setting the requiredInterface
property on the NWParameters
. However:
-
You’re using multicast, and
NWConnection
isn’t the right type to use for that. Rather, you should be usingNWConnectionGroup
with anNWMulticastGroup
descriptor. -
In theory that should also support
requiredInterface
, but I’ve had a lot of troubles getting that API to support things like this.
So, the above should give you some paths to explore. If you get stuck, reply here with the details and I’ll take another look.
ps I have a bunch of background info on this topic inBroadcasts and Multicasts, Hints and Tips.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"