Just had a question regarding the streamStatus of a NSStream. In my application I have an input stream and an output stream that work well in sending and receiving data. Earlier, however, I've noticed that should the server go down I wasn't receiving any notification on the client side that the connection broke. After several weeks of trying to research this and implementing various tests I found that none of them provided me with a proper response to an improper server disconnect or crash. I then created a timer that fired off every 5 seconds and called a function that checked the streamStatus. Upon disconnecting the server by disabling the LAN connection I noticed the client still registering as being connected. When I started to debug the client I noticed that streamStatus always returned NSStreamStatusOpen
on both my input and output streams.
Is there something that I am missing on my end that I am not doing? I have attached below a small snippet of how I am calling and receiving the streamStatus.
Initializing the timer (Called after a successful connection):
connectionTimer = [NSTimer scheduledTimerWithTimeInterval:5.0 target:self selector:@selector(CheckStream) userInfo:nil repeats:YES];
Checking the streams:
- (void)CheckStream
{
NSStreamStatus status = [input streamStatus];
if(status == NSStreamStatusClosed || status == NSStreamStatusError)
{
NSLog(@"Error: %d", status);
}
status = [output streamStatus];
if(status == NSStreamStatusClosed || status == NSStreamStatusError)
{
NSLog(@"Error: %d", status);
}
}