Sample code for 30+ languages & platforms
Rust

Send Bytes on a Socket Connection

See more Socket/SSL/TLS Examples

Demonstrates how to send a mixture of binary (non-text) and text bytes on a socket connection.

Chilkat Rust Downloads

Rust

// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

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

// Connect to some host:port
let ssl = false;
let max_wait_millisec = 20000;
let port = 5555;
if socket.connect("test.com", port, ssl, max_wait_millisec).is_err() {
    println!("{}", socket.last_error_text());
    return;
}

// We wish to send a 0x00 byte followed by the us-ascii string "10800"
let bd = chilkat::BinData::new();

let _ = bd.append_byte(0);
let _ = bd.append_string("10800", "utf-8");

// Send the entire contents of bd.
if socket.send_bd(&bd, 0, 0).is_err() {
    println!("{}", socket.last_error_text());
    return;
}