Sample code from Stream Programming Guide:
- (void)stream:(NSStream *)stream handleEvent:(NSStreamEvent)eventCode {
switch(eventCode) {
case NSStrea
Calling read:maxLength:
once will work. If you do not read all of the available data then you will receive another HasBytesAvailable
event.
Looping to read all of the data can be a problem. If data continues to arrive then you may starve other tasks scheduled on that run loop. If you instead only read once then other run loop tasks will be allowed to run before the next HasBytesAvailable
event is delivered.