I need to connect to a remote host and exchange data with some binary protocol. I'm connecting with:
CFStreamCreatePairWithSocketToHost(NULL, (CFStringRef)@"whatever.host.com",
port, &readStream, &writeStream);
Everything is fine, except the error handling. I'm
- handling
NSStreamEventErrorOccurred
in my stream's delegate - retrieving the error with
theError = [stream streamError];
- trying to get user-friendly error text with
[theError localizedDescription]
.
And here is the problem: instead of nice error message, like 'Host not found', I get "Operation could not be completed. (NSUnknownErrorDomain error 8.)"
Or, when the device is in Airplane mode, I get "The operation couldn’t be completed. (kCFErrorDomainCFNetwork error 2.)"
Question: how do I get a socket connection, where I can retrieve proper error messages? When I used NSURLConnection (in another app), the error messages were nice and friendly, so I'd like to get something similar.