Apple has a relatively new (I think introduced in 2018) "Network.framework" Swift API [1] for working with raw sockets.
Maybe this post is dealing with the layer below - I'm out of my comfort zone with networking - but I recently built a custom protocol using Network and it's working well for me so far.