This project is a learning-focused TCP chat server built in Rust. It is designed as a starting point for a more complex distributed chat system.
- TCP server listening on
127.0.0.1:8080 - Accepts a single client connection
- Reads messages from the client and prints to
stdout - Echoes the message back to the client
- Handles message boundaries using
\n - Supports a simple JSON message protocol with fields:
{ "type": "message", "user": "username", "text": "hello" }- Rust >= 1.70
- Cargo
- Dependencies:
[dependencies]
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"git clone <repo-url>
cd chat-server
cargo run- Open terminal 1 → run the server:
cargo run
- Open terminal 2 → connect as a client:
telnet 127.0.0.1 8080
- Send a JSON message:
{ "type": "message", "user": "zviel", "text": "hello" } - Verify the server prints the message and the client receives the echo back.
src/
├── main.rs # Entry point
├── connection.rs # TcpStream management
├── protocol.rs # Parsing and message definition
- Multi-client support
- Async / Tokio
- Rooms / Channels
- Authentication
- TLS / Security
- Distributed nodes
- No async yet
- Only valid JSON messages are accepted
- Avoid unnecessary cloning
- Document each module clearly
- Understand ownership and borrowing
- Handle streaming data safely
- Manage TCP connections and message boundaries
- Set up modular architecture for future async and distributed features