The method that is called is again - (void)stream:(NSStream *)theStream handleEvent:(NSStreamEvent)streamEvent
. It is up to you to detect which kind of event happened, and to react in a proper way.
E.g., consider the following example from Apple's documentation:
- (void)stream:(NSStream *)stream handleEvent:(NSStreamEvent)streamEvent {
switch(streamEvent) {
case NSStreamEventHasBytesAvailable:;
// whatever...
break;
case NSStreamEventEndEncountered:;
[self processIncomingBytes];
if (stream == ostream) {
// When the output stream is closed, no more writing will succeed and
// will abandon the processing of any pending requests and further
// incoming bytes.
[self invalidate];
}
break;
case NSStreamEventErrorOccurred:;
NSLog(@"HTTPServer stream error: %@", [stream streamError]);
break;
default:
break;
}
}