🇺🇸 English / 🇰🇷 한국어 / 🇨🇳 中文 / 🇪🇸 Español
This project is a high-performance socket server framework implementing the Reactor-Worker pattern with epoll-based asynchronous I/O and thread pool architecture. The framework provides a modular foundation for building scalable network applications such as chat servers, game servers, and distributed systems.
- Event-Driven Architecture – Built on the Reactor pattern for efficient I/O multiplexing
- Asynchronous Processing – Non-blocking I/O operations with thread pool-based message processing
- Protocol Flexibility – Support for both TCP and UDP transport protocols
- Message Format Agnostic – Pluggable parsers for JSON, Protobuf, and custom formats
- Production-Ready – Comprehensive error handling, logging, and resource management
Reactor Layer
ReactorTCPandReactorUDPimplementations for protocol-specific event handling- epoll-based I/O multiplexing for efficient connection management
- Non-blocking socket operations with event notification
Session Management
ClientSessionTCPandClientSessionUDPfor connection state management- Protocol-specific session lifecycle handling
- Resource cleanup and connection tracking
Message Processing Pipeline
FilterChainfor request preprocessing and validationMessageDispatcherfor routing messages to appropriate handlersEventRegistryfor dynamic handler registration
Threading Model
ThreadPoolimplementation for scalable worker management- Producer-consumer pattern with message queues
- Configurable worker thread count
- Language: C++17
- I/O Model: epoll (Linux)
- Concurrency: Thread pool with message queues
- Message Formats: JSON (RapidJSON), Protocol Buffers
- External Dependencies: Redis (hiredis), MySQL, Google Test
- Build System: GNU Make with automated dependency management
sudo apt update
sudo apt install -y g++ cmake makegit clone <repository-url>
cd socket-server-framework
make download # Install dependencies
make # Build the project
./build/server # Run the serverThe server starts with the default configuration from ServerConfig and uses the TestJSONEventHandler.
#include "IEventHandler.h"
#include "ClientRequest.h"
#include "Logger.h"
class CustomEventHandler : public IEventHandler {
public:
std::unordered_map<std::string, HandlerFunc> createHandlers() const override {
return {
{"LOGIN", [this](const ClientRequest& request) { handleLogin(request); }},
{"MESSAGE", [this](const ClientRequest& request) { handleMessage(request); }}
};
}
private:
void handleLogin(const ClientRequest& request) {
Logger::info("User login: " + request.toString());
// Implementation logic
}
void handleMessage(const ClientRequest& request) {
Logger::info("Message received: " + request.toString());
// Implementation logic
}
};#include "Server.h"
#include "CustomEventHandler.h"
int main() {
CustomEventHandler handler;
auto server = Server::Builder()
.setPort(9090)
.setWorkerCount(4)
.setTransportProtocol("TCP") // or "UDP"
.setMessageType("json-rapid") // or "json", "protobuf"
.setEventHandler(handler)
.build();
server->run();
return 0;
}#include "IFilter.h"
class AuthenticationFilter : public IFilter {
public:
bool process(ClientRequest& request) override {
// Authentication logic
return true; // Continue processing
}
};
// Add to server
.addFilter(std::make_unique<AuthenticationFilter>())# Build the project first
make
# Build Docker image
docker build -t socket-server-framework .docker run --rm -p 8080:8080 socket-server-frameworkmake download # Download and build external dependencies
make # Build the server executable
make test # Run unit tests
make clean # Remove build artifacts
make clean-all # Remove build artifacts and dependenciessrc/
├── main.cpp # Application entry point
├── server/
│ ├── Server.h/.cpp # Main server class with Builder pattern
│ ├── ServerConfig.h/.cpp # Configuration management
│ ├── reactor/ # Event loop implementations
│ │ ├── Reactor.h # Abstract reactor interface
│ │ ├── ReactorTCP.cpp # TCP-specific reactor
│ │ └── ReactorUDP.cpp # UDP-specific reactor
│ ├── session/ # Connection management
│ │ ├── ClientSessionTCP.cpp
│ │ └── ClientSessionUDP.cpp
│ ├── threadpool/ # Worker thread management
│ ├── dispatcher/ # Message routing
│ ├── filter/ # Request preprocessing
│ ├── handler/ # Event handlers
│ └── messages/ # Message parsing
└── utils/ # Utility functions
The project includes comprehensive unit tests using Google Test framework:
make testTest coverage includes:
- Server initialization and configuration
- Worker queue operations
- Client session management
- Filter chain processing
This project is available under multiple licensing options:
- Educational Use: Free for learning and educational purposes
- Personal & Small Projects: MIT License
- Enterprise & Commercial: Requires separate licensing agreement
See the LICENSE file for detailed terms.
We welcome contributions to improve the framework:
- Fork the repository
- Create a feature branch
- Implement changes with appropriate tests
- Submit a pull request
For bug reports and feature requests, please use GitHub Issues.

