UDP Broadcast with Network

I'm relatively new to socket networking, and am migrating an older project from CocoaAsyncSocket to Swift's native Network.

The project utilises GCDAsyncUdpSocket.enableBroadcast(_ flag: Bool), but I don't know how to replicate this in Network.

How do I enable UDP Broadcast on NWConnection?

Answered by DTS Engineer in 883293022

Network framework has significant limitations when it comes to handling UDP broadcasts. We talk about these in TN3151 Choosing the right networking API. If you actually need to use broadcasts, check out my advice in Extra-ordinary Networking > Broadcasts and Multicasts, Hints and Tips.

The emphasis there being need. I see a lot of folks using broadcasts for stuff that would be better served by Bonjour service discovery.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Network framework has significant limitations when it comes to handling UDP broadcasts. We talk about these in TN3151 Choosing the right networking API. If you actually need to use broadcasts, check out my advice in Extra-ordinary Networking > Broadcasts and Multicasts, Hints and Tips.

The emphasis there being need. I see a lot of folks using broadcasts for stuff that would be better served by Bonjour service discovery.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

UDP Broadcast with Network
 
 
Q