This repository contains four small Rust-based projects designed to help understand and practice the async
/await
concurrency model in Rust. It includes both synchronous and asynchronous echo clients and servers.
.
├── echo-client-std # A basic synchronous TCP client using Rust std library
├── echo-client-tokio # An asynchronous TCP client using Tokio
├── pattu # A basic synchronous TCP echo server
└── pattu-handler # An asynchronous server that acts as a proxy to 'pattu'
The primary goal of these projects is to get hands-on experience with:
- Writing TCP clients and servers in Rust
- Understanding blocking vs. non-blocking I/O
- Learning how to use
tokio
for asynchronous programming - Handling concurrent connections with
tokio::spawn
- Tokio (for async projects)
You can install dependencies by adding this to your Cargo.toml
:
[dependencies]
tokio = { version = "1", features = ["full"] }
Make sure you have Rust installed. Then, open separate terminal windows and run the following in order:
cd pattu
cargo run --release -- 500 # Optional delay in ms (default: 0)
cd ../pattu-handler
cargo run --release
cd ../echo-client-tokio
cargo run --release
cd ../echo-client-std
cargo run --release
echo-client-std
: Connects directly topattu
on port1234
, sends a message, and receives a response.echo-client-tokio
: Connects topattu
on port8000
asynchronously.pattu
: A basic echo server with optional response delay.pattu-handler
: Acts as a proxy server between client andpattu
, showcasing nested async TCP calls.
- Difference between blocking and non-blocking I/O in Rust
- How to use
tokio::spawn
to handle multiple connections - How to manage TCP streams asynchronously using
AsyncReadExt
andAsyncWriteExt
- Basic server-client communication using TCP sockets
To clean up all build artifacts:
cargo clean
Aryan Bhattarai
This project was made for learning purposes — feel free to fork and try it yourself!
This project is licensed under the MIT License.