does Apple actually provide a readily available WebSocket connection?
Yes. It’s very easy to set up if you’re using the latest API:
let connection = NetworkConnection(to: endpoint) {
WebSocket {
TLS() // or TCP()
}
}
See WWDC 2025 Session 250 Use structured concurrency with Network framework for more about that API.
With the original NWConnection API it requires a bit more ceremony. See this forums post. Oh, and that thread also has code for the original Network framework C API.
Share and Enjoy
Quinn “The Eskimo!” @ DTS @ Apple