Sample code for 30+ languages & platforms
B4X

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 B4X Downloads

B4X
Dim success As Boolean = False

Dim socket As ChilkatSocket
socket.Initialize("socket")

'  Connect to the server using TLS.
Dim bTls As Boolean = True
Dim maxWaitMs As Int = 5000
success = socket.Connect("example.com", 5000, bTls, maxWaitMs)
If success = False Then
    Log(socket.LastErrorText)
    Return
End If


'  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 Then
    Log(socket.LastErrorText)
    Return
End If

Log("Reverted to a plain TCP connection.")