After making some changes to my app for iOS 6 (none of them actually pertaining to networking), I started encountering a strange error with my stream event handler. This is occurring on both iOS 5 and iOS 6, however much more frequently on iOS 5. This error occurs every 50 seconds or so, my stream event handler encounters NSStreamEventErrorOccurred
. The error information is as follows:
Application[6370:707] Error Occured with stream [<__NSCFInputStream: 0xd622ab0>]
Application[6370:707] Stream Status: 7
Application[6370:707] Error Code: 57
Application[6370:707] Error Desc: The operation couldn’t be completed. Socket is not connected
Application[6370:707] Error Reason: Socket is not connected
Application[6370:707] Error Domain: NSPOSIXErrorDomain
Following this error, the handler will encounter a couple 'Connection Reset by Peer' TCP errors, which I believe to be caused by the server sending an RST Packet. Is there any other scenario that can cause this error? My app is connecting to a hardware device that broadcasts a wifi network in AP mode.
The following is my code for the NSStreamEventHasBytesAvailable
event.
case NSStreamEventHasBytesAvailable: {
NSLog(@"Stream has bytes available! Stream is %@", stream);
if (stream == iStream)
{
@try {
uint8_t buf[2048];
unsigned int len = 0;
len = [(NSInputStream *)stream read:buf maxLength:2048];
if(len) {
NSString *incomingData = [[NSString alloc] initWithBytes:(const void *)buf length:len encoding:NSUTF8StringEncoding];
}
} catch (NSException *e) {
NSLog(@"Caught Exception: %@",e);
}
}
break;
}
Please request information as needed, thank you for your time!