dynamic_tcp_stream

Crates.iodynamic_tcp_stream
lib.rsdynamic_tcp_stream
version0.1.0
sourcesrc
created_at2024-08-19 23:19:34.396361
updated_at2024-08-19 23:19:34.396361
descriptionTrait that enables TcpStream to read and write any length messages easily and efficiently.
homepage
repositoryhttps://github.com/LWEdslev/dynamic_tcp_stream
max_upload_size
id1344583
size3,477
Lasse Edslev (LWEdslev)

documentation

README

DynamicTcpStream

Trait that enables TcpStream to read and write any length byte arrays easily.

This is acheived through prefixing the message with 4 bytes describing the message length.

Example:

// simply import the `DynamicTcpStream` trait
use dynamic_tcp_stream::DynamicTcpStream;

// for a `std::net::TcpStream`
let mut stream = TcpStream::connect("127.0.0.1:8080").unwrap();

// you can now send any message 
stream.write_entire_message(b"Hello world").unwrap();

// and the exact message will be received regarding length
let received = stream.read_entire_message().unwrap();
Commit count: 0

cargo fmt