Sample code for 30+ languages & platforms
Zig

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

Zig
const std = @import("std");
const chilkat = @import("chilkat");

pub fn main(init: std.process.Init) !void {
    const alloc = init.arena.allocator();

    const socket = try chilkat.Socket.init();
    defer socket.deinit();

    // Connect to the server using TLS.
    const b_tls = true;
    const max_wait_ms = 5000;
    socket.connect("example.com", 5000, b_tls, max_wait_ms) catch {
        std.debug.print("{s}\n", .{try socket.getLastErrorText(alloc)});
        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.
    socket.convertFromSsl() catch {
        std.debug.print("{s}\n", .{try socket.getLastErrorText(alloc)});
        return;
    };

    std.debug.print("Reverted to a plain TCP connection.\n", .{});
}