Sample code for 30+ languages & platforms
Rust

Duplicate a Socket Wrapper Sharing the Connection

See more Socket/SSL/TLS Examples

Demonstrates Socket.DupSocket, which populates a destination Socket with another wrapper that shares this object's underlying connection.

Background. The shared connection is reference-counted, and all wrappers operate on the same live connection. The destination first releases any connection it previously held.

Chilkat Rust Downloads

Rust

let socket = chilkat::Socket::new();

// Connect to the server using TLS.
let b_tls = true;
let max_wait_ms = 5000;
if socket.connect("example.com", 5000, b_tls, max_wait_ms).is_err() {
    println!("{}", socket.last_error_text());
    return;
}

// Create a second Socket wrapper that shares this object's underlying connection.  Both wrappers
// operate on the same live connection; the shared connection is reference-counted.
let dup_sock = chilkat::Socket::new();
if socket.dup_socket(&dup_sock).is_err() {
    println!("{}", socket.last_error_text());
    return;
}

println!("Duplicate socket wrapper created.");