I'm currently working on an iOS-App and i need to connect to another device. The NWConnection is successfully established using TCP and I can receive one (and only one) message from the remote device and get an error immediately. The connection gets cancelled (caused by the error I guess). The console log shows:
Hello World.
[connection] nw_flow_add_read_request [C1 <ip and port of remote device> ready channel-flow (satisfied (Path is satisfied), viable, interface: en0, ipv4, ipv6, dns)] already delivered final read, cannot accept read requests
[connection] nw_read_request_report [C1] Receive failed with error "No message available on STREAM"
error
My code looks like this:
private func setupReceive() {
NWCon!.receive(minimumIncompleteLength: 1, maximumLength: 65536) { (data, _, isComplete, error) in
if let data = data, !data.isEmpty {
let message = String(data: data, encoding: .utf8)
if(message!.contains("Hello World")) {
print("Hello World.")
} else if(message == "Closing connection!") {
//...
}
}
if error != nil { print("error: \(error)") }
else { self.setupReceive() }
}
}
The remote device only sends one package and to receive further packages, the method gets called again.
EDIT: I printed the error message and got
error: Optional(POSIXErrorCode: No message available on STREAM)
which seems to refer to POSIXError ENODATA.