Sample code for 30+ languages & platforms
Rust

Receive Bytes into a BinData

See more Socket/SSL/TLS Examples

Demonstrates Socket.ReceiveBd, which receives one delivery of binary data and appends it to a BinData. It returns whatever is immediately available.

Background. The BinData receive methods accumulate raw bytes in a BinData object. A single receive returns only what is currently available, whereas the counted receive waits for an exact number of bytes.

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;
}

// Receive one delivery of binary data and append it to a BinData.  ReceiveBd returns whatever is
// immediately available; it does not loop to drain everything that may follow.
let bd = chilkat::BinData::new();
if socket.receive_bd(&bd).is_err() {
    println!("{}", socket.last_error_text());
    return;
}

println!("Received {} bytes.", bd.num_bytes());