Sample code for 30+ languages & platforms
Rust

Move a Connection into Another Socket

See more Socket/SSL/TLS Examples

Demonstrates Socket.TakeConnection, which moves the active connection from one Socket into another. The receiving object first releases any connection it previously held.

Background. Unlike TakeSocket, TakeConnection does not add a member to a socket set. After success, the source socket holds no connection. This is useful for handing an accepted connection to a dedicated handler object.

Chilkat Rust Downloads

Rust

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

if listen_sock.bind_and_listen(5000, 25).is_err() {
    println!("{}", listen_sock.last_error_text());
    return;
}

let connected_sock = chilkat::Socket::new();
if listen_sock.accept_next(20000, &connected_sock).is_err() {
    println!("{}", listen_sock.last_error_text());
    return;
}

// Move the active connection out of connectedSock and into another Socket object.  Unlike
// TakeSocket, this does not add a member to a socket set.  After success, connectedSock holds no
// connection.
let handler_sock = chilkat::Socket::new();
if handler_sock.take_connection(&connected_sock).is_err() {
    println!("{}", handler_sock.last_error_text());
    return;
}

println!("Connection moved to the handler socket.");