Swift
Swift
Revert a TLS Connection to Plain TCP
See more Socket/SSL/TLS Examples
Demonstrates Socket.ConvertFromSsl, which ends the TLS layer while leaving the underlying TCP connection open for subsequent unencrypted communication.
Background. This is the reverse of a STARTTLS-style upgrade and is valid only while TLS is currently active on the connection.
Chilkat Swift Downloads
func chilkatTest() {
var success: Bool = false
let socket = CkoSocket()!
// Connect to the server using TLS.
var bTls: Bool = true
var maxWaitMs: Int = 5000
success = socket.connect(hostname: "example.com", port: 5000, ssl: bTls, maxWaitMs: maxWaitMs)
if success == false {
print("\(socket.lastErrorText!)")
return
}
// End the TLS layer while keeping the underlying TCP connection open for subsequent unencrypted
// communication. This is the reverse of a STARTTLS-style upgrade and is valid only while TLS is
// active.
success = socket.convertFromSsl()
if success == false {
print("\(socket.lastErrorText!)")
return
}
print("Reverted to a plain TCP connection.")
}