Hi,
I'm using SPM to extract the networking component of an app into a package. Part of what I thought I'd get, by doing that, is to be able to build a command-line-tool to make testing quicker. The tool is essentially like a ping command built on top of the network package, that I can use to test the networking logic while I simulator various conditions with the Cloud API (offline, busy, etc).
However, it's the first command line tool I've built. And I'm learning that I need to learn more about command line tool building 🙂
This is a fairly standard method to set the stateUpdateHandler (in my networking package). It works fine in the iOS simulator, but doesn't get called when used in the command line tool. But, I call a .send() after starting the connection and in both cases the data is sent to the remote side ('nc -l 80').
Can anyone recommend some good resources to learn, that will help me figure out why the below doesn't work on the command line?
thanks
func startConnection() {
guard let connection = connection else {
return
}
// A handler that receives connection state updates.
connection.stateUpdateHandler = { newState in
switch newState {
case .setup:
print("setup: \(connection)")
case .preparing:
print("preparing: \(connection)")
case .ready:
print("established: \(connection)")
case .waiting(let error):
print("\(connection) waiting with \(error)")
case .failed(let error):
print("\(connection) failed with \(error)")
default:
break
}
}
connection.start(queue: .main)
}