Rust
Rust
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 Rust Downloads
let socket = chilkat::Socket::new();
// Connect as plain TCP (no TLS yet).
let b_tls = false;
let max_wait_ms = 5000;
if socket.connect("example.com", 5000, b_tls, max_wait_ms).is_err() {
println!("{}", socket.last_error_text());
return;
}
// 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.
if socket.convert_to_ssl().is_err() {
println!("{}", socket.last_error_text());
return;
}
println!("Connection upgraded to TLS.");