While going through the documentation for NWConnection, there seems to be state known as .waiting which means that the connection is waiting for a path change. For TCP, the state is understandable and can occur under some scenarios. But for the case of UDP, I have following queries:
- Why do we need
.waitingstate for the case of UDP? - Even if we do need
.waitingstate for UDP, when all does this state occurs?
NWConnection is quite generic, so you shouldn’t be surprised that not all of its options make sense for all connection types [1]. However, in this case the .waiting state does make sense for UDP. Consider a connection created like this:
let connection = NWConnection(to: .hostPort(host: "example.com", port: 80), using: .udp)
If you run this on a device with Airplane Mode enabled, the connection will enter the .waiting state. That’s because it’s waiting for DNS to come online so that it can resolve example.com to find out what addresses it should attempt to ‘connect’ to.
But that’s just an example. I suspect that are a number of other cases where you’ll see this.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"
[1] The new NetworkConnection API improves this situation, using the Swift type system to vary the operations supported on the connection based on the underlying protocol. However, there are limits to how much you can improve this. Like with onions, the finer you chop, the more likely it is that things will end it tears (-: