Getting Started
All examples can be executed from the Tokio repository with:hello_world and echo-tcp examples to understand the basics of async networking with Tokio.
Available Examples
Hello World
A simple TCP client that connects and writes data
Echo TCP Server
A concurrent TCP echo server demonstrating basic async I/O patterns
Chat Server
A multi-client chat server with message broadcasting
TCP Client
Connect stdin/stdout to a TCP stream for interactive communication
Proxy Server
Forward data between clients and backend servers
Custom Executor
Integrate Tokio runtime with custom executors
Example Categories
Networking Basics
Hello World
Hello World
A minimal TCP client that opens a connection, writes “hello world”, and closes.Use case: Understanding basic async TCP connectionsKey concepts:
TcpStream::connect()AsyncWriteExttrait#[tokio::main]macro
TCP Client (connect-tcp)
TCP Client (connect-tcp)
An interactive client that hooks up stdin/stdout to a TCP stream, allowing you to type messages and receive responses.Use case: Testing TCP servers interactivelyKey concepts:
- Framed I/O with codecs
- Stream and Sink traits
- Bidirectional communication
Proxy Server
Proxy Server
A TCP proxy that forwards data between clients and a backend server using
copy_bidirectional.Use case: Load balancing, protocol translation, debuggingKey concepts:copy_bidirectional()- Concurrent connection handling
- Forwarding patterns
Server Examples
These examples demonstrate building production-ready servers with Tokio:- Echo TCP Server - Learn concurrent connection handling and basic I/O patterns
- Chat Server - Explore message broadcasting, shared state, and the
select!macro - UDP Examples - UDP echo server and client implementations
Advanced Topics
Custom Executor
Learn how to integrate Tokio with other executor frameworks using
TokioContext.Topics covered:- Custom runtime integration
- Context management
- Thread pool coordination
Real-World Example
For a larger, production-quality example, check out mini-redis, a Redis implementation built with Tokio. It demonstrates:- Command parsing and execution
- Connection pooling
- Error handling patterns
- Testing async code
- Production-ready architecture
The Tokio tutorial provides guided walkthroughs of several examples with detailed explanations.
Contributing Examples
Have an example you’d like to see? Open an issue in the Tokio repository. If you’ve built something useful, pull requests are welcome!Next Steps
Start with Echo Server
Build your first concurrent TCP server
Build a Chat App
Learn message broadcasting and state management