IOS StreamStatus always returns NSStreamStatusOpen

Just a question about streamStatus for NSStream. In my application, I have an input stream and an output stream that work well when sending and receiving data. Before, however, I noticed that if the server went down, I did not receive a client-side notification that the connection was broken. After a few weeks, trying to investigate this and implement various tests, I found that none of them gave me the proper answer to the wrong shutdown or server crash. Then I created a timer that started every 5 seconds and called a function that checked streamStatus. After turning off the server, disconnecting the connection to the local network, I noticed that the client is still registered as connected. When I started debugging the client, I noticed that streamStatus always returned NSStreamStatusOpen for both input and output streams.

Is there something that I am missing in the end that I am not doing? I have added below a small snippet of how I call and receive streamStatus.

Initialization of the timer (called after a successful connection):

 connectionTimer = [NSTimer scheduledTimerWithTimeInterval:5.0 target:self selector:@selector(CheckStream) userInfo:nil repeats:YES]; 

Stream Check:

 - (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); } } 
+4
source share

Source: https://habr.com/ru/post/1399850/


All Articles