How can I send a UDP message to all link local nodes using apple's Network framework?

289 Views Asked by At

When I try to setup a connection, it changes from waiting(POSIXErrorCode: Network is down) to preparing state. But it never goes into the ready state and I can't figure out how to send a datagram.

import Network
import Dispatch

let connection = NWConnection(host: .ipv6(.linkLocalNodes), port: 9898, using: .udp)

connection.stateUpdateHandler = { state in print(state) }
connection.start(queue: DispatchQueue(label: "UDP"))

How can I send a UDP message to all link local nodes?

1

There are 1 best solutions below

0
On

It looks like you need to specify an interface for the link local multicast address. Sending to all interfaces does not work. So for example in my case I have to send to .ipv6(IPv6Address("ff02::1%en4")!) to send to all the local nodes on en4.