OK, that"s what I've supposed. The state .failed is terminal.
This is why I've implemented the re-connection with setupUDPConnection().
However, I'm not quite sure from where to recover.
Here's my condensed implementation of setupUDPConnection():
self.connection.cancel()
let udp = NWProtocolUDP.Options.init()
udp.preferNoChecksum = false
let params = NWParameters.init(dtls: nil, udp: udp)
params.serviceClass = .responsiveData
connection = NWConnection(host: NWEndpoint.Host.name(AppConstant.Web.urlWebSafeSky, nil), port: NWEndpoint.Port(rawValue: AppConstant.Web.urlWebSafeSkyPort)!, using: params)
connection.stateUpdateHandler = { (newState) in
switch (newState) {
case .ready:
self.receiveUDPConnection()
break
case .setup:
// Nop
break
case .cancelled:
// Nop
break
case .preparing:
// Nop
break
case .waiting(let error):
// Nop
break
case .failed(let error):
// Cancel present connection
// break
default:
break
}
self.handleStateChange()
}
connection.start(queue: queue)`
But the connection using the same NWConnection instance (self.connection) does not succeed.
Possibly, because the network reception is still weak. How does one get informed about re-availability of the RF network connection in order to start the above mentioned setupUDPConnection()?
Topic:
App & System Services
SubTopic:
Networking
Tags: