Exploring low-level networking with POSIX sockets, TCP/IP, Linux epoll, and concurrency in C++.
- Multi-threaded TCP Server: Built using Linux
epolland non-blocking sockets for high-performance concurrent client handling. - Thread Pool Architecture: Features a producer-consumer work queue to efficiently process requests under high workloads.
- Custom Binary Protocol: Implements robust message framing and serialization for low-overhead client-server communication.
- Connection Lifecycle Management: Handles client joins, disconnections, socket cleanup, and resource reclamation gracefully.
- Token-Bucket Rate Limiting: Built-in rate limiter to prevent request flooding and ensure fair resource allocation across connected clients.
- Interactive Chat & Commands: Real-time message broadcasting and server metrics tracking (
/ping, stats). - Robust Error Handling: Reusable wrapper functions with descriptive diagnostics.
.
├── include/
│ ├── utils.h # Socket wrapper & non-blocking declarations
│ └── server_core.h # Protocol, thread pool, and rate limiter definitions
├── src/
│ ├── client.cpp # Interactive TCP client
│ ├── server.cpp # Multi-threaded epoll server
│ └── utils.cpp # Wrapper & fcntl implementations
├── build/ # Object files
├── bin/ # Compiled executables
├── Makefile
├── LICENSE
└── README.md
Clone the repository:
git clone https://github.com/Jx-ls/tcp-server-client.git
cd tcp-server-clientCompile the project:
makeThis generates the executables:
bin/server
bin/client
To clean generated files:
make clean./bin/server 8080Server output:
[Server] Listening on port 8080...
./bin/client 127.0.0.1 8080Example client output:
Connected to server successfully!
Type messages or '/ping' to test latency.
> Hello from client!
> /ping
PONG
- C++20
- POSIX Socket API
- Linux System Calls (epoll, fcntl, socket)
- C++ Multithreading (std::thread, std::mutex, std::condition_variable)
- GNU Make
- g++
- TCP/IP networking and client-server architecture
- High-performance I/O multiplexing with edge-triggered (EPOLLET) epoll
- Non-blocking socket configuration using fcntl()
- Producer-Consumer thread pool concurrency patterns
- Token-bucket rate limiting algorithms
- Custom binary packet framing and safe buffer serialization
- Network byte order (htonl, htons) and IP conversion (inet_pton)
- Linux
- g++ (C++20 compatible)
- GNU Make
This project is licensed under the MIT License. See the LICENSE file for details.