AutoIt
AutoIt
Upgrade a Plain TCP Connection to TLS
See more Socket/SSL/TLS Examples
Demonstrates Socket.ConvertToSsl, which upgrades an already-connected plain TCP socket to TLS by performing a client-side TLS handshake over the existing connection.
Background. This supports STARTTLS-style upgrades, where a protocol begins in plaintext and switches to TLS at a defined point. Perform the protocol-specific negotiation first, then call ConvertToSsl.
Chilkat AutoIt Downloads
Local $bSuccess = False
$oSocket = ObjCreate("Chilkat.Socket")
; Connect as plain TCP (no TLS yet).
Local $bTls = False
Local $iMaxWaitMs = 5000
$bSuccess = $oSocket.Connect("example.com",5000,$bTls,$iMaxWaitMs)
If ($bSuccess = False) Then
ConsoleWrite($oSocket.LastErrorText & @CRLF)
Exit
EndIf
; At the point where the application protocol permits a STARTTLS-style upgrade, perform any required
; negotiation, then upgrade the existing connection to TLS with a client-side handshake.
$bSuccess = $oSocket.ConvertToSsl()
If ($bSuccess = False) Then
ConsoleWrite($oSocket.LastErrorText & @CRLF)
Exit
EndIf
ConsoleWrite("Connection upgraded to TLS." & @CRLF)