/rust-tcpstream-demo

Examples of reading/writing data from TcpStream in Rust

Primary LanguageRust

Ready & Writing data with Rust's TcpStream

This repo contains examples of using Rust's TcpStream to send & receive data between a client and server. This example shows low-level data (raw bytes) reading & writing with Rust's TcpStream. Subsequent examples add abstractions over this, but it's helpful to understand what's happening under the hood and why abstractions make things easier.

Raw TCP Bytes

See how the Read and Write traits work with low-level TcpStream Tx/Rx

Line-based Codec

Step up a level of abstraction using line-based messaging (newline delimited) and how the BufRead and BufWrite traits can be more effecient

Message Protocol

If we want to send more than just lines, we can abstract even further into a protocol of structs, handling serialization & deserialization with byteorder