The run loop isn't running long enough for the delegate method to be called.
Add:
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:2.0]];
right after you open the stream. This is only necessary in a program without a GUI -- otherwise the run loop would be spun for you.
If you want to be absolutely sure that stream:handleEvent:
has been called before exiting, set a (global) flag in that method and put the runUntilDate:
in a while
loop that tests for the flag:
while( !delegateHasBeenNotified ){
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.5]];
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…