Sample code for 30+ languages & platforms
Rust

Receive Bytes as Encoded Text from a Socket

See more Socket/SSL/TLS Examples

Demonstrates Socket.ReceiveBytesENC, which receives one delivery of binary data and returns it encoded as text using a named encoding.

Background. The ENC methods move raw binary data to and from printable text using a named encoding such as base64 or hex, which is convenient for logging or for handling binary data as strings.

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 return it encoded as text using the named encoding.  This
// is convenient for logging or transporting binary data as printable text.
let Ok(encoded) = socket.receive_bytes_enc("base64") else {
    println!("{}", socket.last_error_text());
    return;
};

println!("{}", encoded);