Crates.io | dynamic_tcp_stream |
lib.rs | dynamic_tcp_stream |
version | 0.1.0 |
source | src |
created_at | 2024-08-19 23:19:34.396361 |
updated_at | 2024-08-19 23:19:34.396361 |
description | Trait that enables TcpStream to read and write any length messages easily and efficiently. |
homepage | |
repository | https://github.com/LWEdslev/dynamic_tcp_stream |
max_upload_size | |
id | 1344583 |
size | 3,477 |
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.
// 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();