Before we start, two things:
I don’t think anyone with deep SwiftNIO expertise lurks here on DevForums. You'd be better off asking on Swift Forums > Related Project > SwiftNIO.
iOS 13 and friends support a native WebSocket API, including a high-level client based on
URLSessionand a low-level client and server in the Network framework. See WWDC 2019 Session 712 Advances in Networking, Part 1 for the detail.
Coming back to your big picture, you wrote:
I am trying to run a websocket server and client in the same app.
I recommend against doing this. There’s at least two problems you will encounter:
WebSocket requests, being network requests, can fall foul of the web view’s same-origin policy.
Loopback requests like this can run into problem when deployed in a per-app VPN environment.
A better option for web-to-native communication is
If you have a bunch of existing web code that assumes WebSocket semantics, it’s feasible to build a shim that looks like a WebSocket but actually operates in terms of
Share and Enjoy
Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
let myEmail = "eskimo" + "1" + "@apple.com"