Naked Networking with SwiftUI
Network
Back in the dark ages when I entered the world of computing the way to get two computers to talk to each other was to use black magic, also known as sockets.
The techs at Apple who are I must admit are pretty good at developing frameworks decided to put their mind to bringing sockets up to date. They did so with the Network framework, published in 2018.
I hope in this article to go thru a super simple socket implementation. I also hope to dip into SwiftUI while I do so too. I like a challenge.
Where to start. Ok there are two flavours, TCP and UDP. In short TCP sockets guarantee delivery, UDP sockets do not. TCP are useful when you need to be sure the message you sent arrived. UDP sockets are useful when you more concerned about speed.
I am going to focus on UDP for this article, cause they are a tad easier to implement :) and maybe more interesting to the reader, since they are sort of sockets you want to use for that killer game app you been meaning to develop.
Now, as with all conversations we have somebody talking and somebody listening. A socket pair in socketese. On one device you listen and on the other you talk.
Lets start by creating a project, call it nakedNetworking, why not. I am using iOS 13, Swift 5 and Xcode 11.3.1.
Create the project and go with the Hello World template you get when you select SwiftUI interface. Next create a separate file for our…