Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Receiving Error Domain=kCFErrorDomainCFNetwork Code=2 when attempting to read from ReadStream

I'm attempting to synchronously read from a CFReadStream objected created by CFStreamCreatePairWithSocketToHost. The stream opened fine but when I attempt to invoke CFReadStreamRead on it in a loop, CFReadStreamRead() returns -1 and the resulting error is:

Error Domain=kCFErrorDomainCFNetwork Code=2 "The operation couldn’t be completed. (kCFErrorDomainCFNetwork error 2.)" UserInfo=0x14a920 {kCFGetAddrInfoFailureKey=8}

I'm also receiving this same exact error when using this ReadStream asynchronously- the first callback I receive is this error.

like image 300
theactiveactor Avatar asked May 24 '10 14:05

theactiveactor


1 Answers

I was able to eliminate this error by removing https:// from the host String.

NSStream.getStreamsToHostWithName("https://example.com" ...

You may need to set the appropriate security level:

 inputStream!.setProperty(NSStreamSocketSecurityLevelTLSv1, forKey: NSStreamSocketSecurityLevelKey)
outputStream!.setProperty(NSStreamSocketSecurityLevelTLSv1, forKey: NSStreamSocketSecurityLevelKey)
like image 134
Christopher Markieta Avatar answered Sep 21 '22 07:09

Christopher Markieta