I'm working at a simple client that needs to connect to a socket. This socket requires SSL...I'm trying to configure the client to support SSL but I'm getting this error:
CFNetwork SSLHandshake failed (-9807)
This is the code that I've written to configure the socket. Do you see anything strange/wrong? Also... the server is running on localhost and I'm running the iOS app on the simulator at the moment... may it be a problem?
class MySocket:NSObject {
var inputStream: InputStream!
var outputStream: OutputStream!
func setupStream(){
var readStream: Unmanaged<CFReadStream>?
var writeStream: Unmanaged<CFWriteStream>?
CFStreamCreatePairWithSocketToHost(kCFAllocatorDefault,
"127.0.0.1" as CFString,
80,
&readStream,
&writeStream)
inputStream = readStream!.takeRetainedValue()
outputStream = writeStream!.takeRetainedValue()
inputStream.delegate = self
inputStream.schedule(in: .current, forMode: .common)
outputStream.schedule(in: .current, forMode: .common)
// SETTING SSL HERE
inputStream.setProperty(kCFStreamSocketSecurityLevelNegotiatedSSL, forKey: Stream.PropertyKey.socketSecurityLevelKey)
outputStream.setProperty(kCFStreamSocketSecurityLevelNegotiatedSSL, forKey: Stream.PropertyKey.socketSecurityLevelKey)
// END SSL SETUP
inputStream.open()
outputStream.open()
}
}