I might be completely wrong here, but it looks like you can do this line differently
connection = NWConnection(host: host, port: port, using: .udp)
the last parameter doesn't need to be fixed as .udp, the default udp parameters. You can make new NWParameters and alter the value of requiredLocalEndpoint.
hth, and Happy New Year
Topic:
Programming Languages
SubTopic:
Swift
Tags: