Sample code for 30+ languages & platforms
C++

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 C++ Downloads

C++
#include <CkSocket.h>

void ChilkatSample(void)
    {
    bool success = false;

    CkSocket socket;

    //  Connect to the server using TLS.
    bool bTls = true;
    int maxWaitMs = 5000;
    success = socket.Connect("example.com",5000,bTls,maxWaitMs);
    if (success == false) {
        std::cout << socket.lastErrorText() << "\r\n";
        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) {
        std::cout << socket.lastErrorText() << "\r\n";
        return;
    }

    std::cout << "Reverted to a plain TCP connection." << "\r\n";
    }