I have a NWConnection, that if an invalid (ip/port), is entered, I get in debug the error: nw_socket_handle_socket_event [C1.1.1:1] Socket SO_ERROR 61. But I can't seem to trap that error. I have as my stateChangeHandler:
I am creating my connection:
let tcpOptions = NWProtocolTCP.Options()
tcpOptions.enableKeepalive = true
tcpOptions.keepaliveIdle = 2
tcpOptions.keepaliveCount = 2
tcpOptions.keepaliveInterval = 2
let params = NWParameters(tls: nil, tcp: tcpOptions)
nwConnection:NWConnection(host: NWEndpoint.Host(host), port: NWEndpoint.Port(port)!, using: params). (with known nonexistent ip/port).
I was hopping when I did a .start(), I would get an error in my state handler:
// ===============================================================================
func stateDidChange(to state: NWConnection.State) {
Swift.print("State change")
switch state {
case .waiting(let error):
print("Client waiting")
connectionDidFail(error: error)
case .ready:
print("Client connection ready")
case .failed(let error):
print("Client failed")
connectionDidFail(error: error)
case .preparing:
print("client preparing")
case .setup:
print("client setup")
case .cancelled:
print("client cancelled")
default:
print("Client unknown")
break
}
}
But it doesn't trap an error. So, where is this error coming from (I know the cause), but I want to trap it (in case a user puts in a wrong ip/port)