-
Notifications
You must be signed in to change notification settings - Fork 158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
iOS Data Stream example #3134
Comments
So, not sure what I changed but receiving a stream seems to be working now. public func connectionManager(
_ connectionManager: ConnectionManager, didReceive stream: InputStream,
withID payloadID: PayloadID, from endpointID: EndpointID,
cancellationToken token: CancellationToken)
{
print("Received stream from \(endpointID)")
self.stream = stream
let delegate = MPStreamDelegates()
streamDelegate = delegate
stream.delegate = delegate
if stream.delegate === delegate
{
print("Delegate assigned successfully.")
}
else
{
print("Delegate assignment failed.")
}
stream.schedule(in: .main, forMode: .default)
stream.open()
}
class MPStreamDelegates: NSObject, StreamDelegate {
public func stream(_ aStream: Stream, handle eventCode: Stream.Event) {
print("Stream event: \(eventCode)")
switch eventCode {
case .endEncountered:
print("endEncountered")
case .hasBytesAvailable:
if let inputStream = aStream as? InputStream {
let bufferSize = 512
var buffer = [UInt8](repeating: 0, count: bufferSize)
let bytesRead = inputStream.read(&buffer, maxLength: bufferSize)
if bytesRead > 0 {
print("read \(bytesRead)")
} else {
print("No new data available or end of stream.")
break
}
}
case .endEncountered:
print("Stream ended")
aStream.close()
aStream.remove(from: .current, forMode: .default)
case .errorOccurred:
print("Stream error: \(aStream.streamError?.localizedDescription ?? "Unknown error")")
case .openCompleted:
print("Stream opened")
case .hasSpaceAvailable:
print("Stream has space available")
default:
print("Other stream event")
}
}
} logs:
However, I have been unsuccessful actually reading the stream. Not sure what's going on here, on the Multipeer Connectivity framework this stream delegate worked fine. |
So, I was able to fix it. Instead of scheduling the stream when receiving it just open it. and then when receiving a progress update of the stream, manually read it. |
So, turns it isn't fixed, it is now just reading all the data in the beginning of the stream each time. Instead of actually advancing, through the stream. I also see the memory usage continuously increasing over time. |
Okay, so I fixed the repeating data part, but there is still the issue where the memory continues to increase. This is probably related to #2147 |
Hi, I am trying to create two data streams between two iOS devices. However, I have unable to get it to work, and there seems to be no clear example in the documentation.
Here is how I create the Stream objects (this runs when a connection has been successfully established):
And then the receiving of the streams:
For testing purposes, I send 10 bytes 4x per second.
On the receiving end, I get this error:
I tried modifying feature flags to see if that would resolve the issue, but was unsuccessful.
Would be great if someone could share a working example!
Thanks in advance
The text was updated successfully, but these errors were encountered: