Skip to content

RajMandaliya/rust-chat-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Rust Chat Server

An asynchronous TCP chat server built in Rust, designed to demonstrate concurrency, networking, and clean system architecture using Tokio.

This project focuses on correctness, clarity, and real-world async patterns rather than UI or frameworks.


Highlights

  • Async networking with Tokio (async/await)
  • Concurrent client handling using lightweight tasks
  • Clean modular architecture (server, client, message handling)
  • Structured logging with tracing
  • Designed to be extensible (broadcasting, rooms, auth, protocols)

What This Project Demonstrates

This repository showcases:

  • How to design a long-running async TCP server in Rust
  • Safe concurrency and task spawning
  • Separation of concerns in systems code
  • Practical error handling and observability
  • Production-oriented Rust patterns (no println! debugging)

It is intentionally framework-light to emphasize core systems understanding.


Architecture Overview

src/

β”œβ”€β”€ main.rs # Application entrypoint, logging, startup

β”œβ”€β”€ server.rs # TCP listener and connection accept loop

β”œβ”€β”€ client.rs # Per-client connection handling

β”œβ”€β”€ message.rs # Message types / protocol (extensible)

└── state.rs # Shared chat state (for future features)

Each module has a single responsibility, making the system easy to reason about and extend.


Getting Started

Prerequisites

  • Rust (stable)
  • Cargo

Run the server

cargo run

Server starts on:

127.0.0.1:8080

Connect with a client

nc 127.0.0.1 8080

Multiple clients can connect concurrently.

Tech Stack

Language: Rust

Async Runtime: Tokio

Logging: tracing / tracing-subscriber

Concurrency Model: async tasks, non-blocking I/O

Current Behavior

Accepts multiple TCP clients concurrently

Reads messages from clients

Echoes messages back (baseline behavior)

Logs connection lifecycle events

This forms a solid foundation for richer chat semantics.

Planned Extensions

Message broadcasting to all connected clients

Chat rooms / channels

Message protocol with enums & serialization

Graceful shutdown handling

Load & stress testing

Authentication / authorization

πŸ“Œ Related Projects

Async Pipeline (Rust): High-throughput async processing architecture

About

Async chat server in Rust demonstrating concurrency, networking, and clean architecture

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages