Can anybody know which method is called when socket is automatically disconneted in NSStreamDelegate ? Because when socket is disconnected then its will again called - (void)stream:(NSStream *)theStream handleEvent:(NSStreamEvent)streamEvent
method so it will create lots of problem. Can anybody tell me how to handle socket disconnection ?
Asked
Active
Viewed 297 times
0

Akshay Aher
- 2,525
- 2
- 18
- 33

Nrml
- 31
- 3
1 Answers
0
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;
}
}

Matthias
- 8,018
- 2
- 27
- 53