How to handle a connection timing out?
// `endpoint` was obtained from a bonjour browser
let connection = NWConnection(to: endpoint, using: .tcp)
connection.stateUpdateHandler = { [self] newState in
print("newState: \(newState)")
}
connection.start(queue: .main)
Log:
newState: preparing
nw_socket_handle_socket_event [C1.1.4.1:1] Socket SO_ERROR [60: Operation timed out]
... several more times
The stateUpdateHandler function is never called again.
9
0
2k