Rust
Rust
Receive Bytes up to a Delimiter into a BinData
See more Socket/SSL/TLS Examples
Demonstrates Socket.ReceiveUntilByteBd, which reads bytes until a delimiter byte is encountered and appends all bytes up to and including the delimiter to a BinData.
Background. The delimiter is a raw byte value from 0 through 255. This is useful for framing schemes that terminate each message with a known delimiter byte.
Chilkat Rust Downloads
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;
}
// Read bytes until the delimiter byte is encountered, appending all bytes up to and including the
// delimiter to a BinData. The delimiter is a raw byte value from 0 through 255 (here the linefeed
// byte, decimal 10).
let bd = chilkat::BinData::new();
if socket.receive_until_byte_bd(10, &bd).is_err() {
println!("{}", socket.last_error_text());
return;
}
println!("Received {} bytes (including the delimiter).", bd.num_bytes());