The sample shows two different things:
The first is the most general one. The second is specific to DeviceDiscoveryUI, which allows the app running on tvOS to easily connect to an instance of the app running on iOS, iPadOS, and watchOS.
In reality, most real apps do one or the other, not both. So, unless your specifically concerned with the tvOS case, I recommend that you ignore all the application services stuff.
it seems like the listener is just used for setting up the connection
Yes. You have a listener that ‘vends’ connections and you do all your I/O on the connections.
This is a common idiom in networking APIs. For example, in BSD Sockets you have a listening socket that ‘vends’ connection sockets via the accept
system call.
Network framework uses different types for these two things because they have very different semantics. In BSD Sockets you can call send
on a listener socket, and that won’t do anything useful. But in Network framework, with its separate listener and connection types, we added the send and receive APIs as methods on the connection type only.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"