I am trying to send data between an iPhone and a BeagleBone Black Wireless over TLS. However, I am encountering some strange issues. The issue that this question is about is why the delegate method stream(_:handle:)
is not called. I've read the documentation and the other StackOverflow questions, but my code already takes into account their issues.
Here are my variables:
private var readStream: Unmanaged<CFReadStream>?
private var writeStream: Unmanaged<CFWriteStream>?
private var inputStream: InputStream?
private var outputStream: OutputStream?
And here is my code for opening the streams:
CFStreamCreatePairWithSocketToHost(kCFAllocatorDefault, (socket.ipAddress as CFString), UInt32(socket.port), &readStream, &writeStream)
outputStream = writeStream?.takeRetainedValue()
inputStream = readStream?.takeRetainedValue()
outputStream?.delegate = self
inputStream?.delegate = self
outputStream?.schedule(in: .current, forMode: .default)
inputStream?.schedule(in: .current, forMode: .default)
outputStream?.open()
inputStream?.open()
This is the delegate method exactly as it appears in my code (it is autocompleted by Xcode, so no issue there):
private func stream(_ aStream: Stream, handle eventCode: Stream.Event) {
print("Received event code \(eventCode.rawValue)")
}
For some reason though, this method never gets called. In fact, I tried sending data, by writing to outputStream
, and the BBBW actually received the message successfully! (Although, if I try to send a message again, I get a Connection reset by peer
error.)
Ah I figured it out!
The issue was that I made the delegate method
private
. Once I got rid of that keyword, everything worked out :)