A multi-threaded TCP server system in C demonstrating advanced concepts of concurrent programming and network communication.
- Thread Pool – Limit of 10 simultaneous threads controlled by a semaphore
- LRU Cache – Thread-safe cache system with a Least Recently Used policy
- Asynchronous Logging – Dedicated thread with a circular buffer of 1000 messages
- Load Balancer – Round-robin distribution across up to 5 servers
- Plugin System – Dynamic loading of DLLs (Windows) or .so files (Linux)
- TCP Socket – Basic HTTP server on port 9090
Windows: MinGW-w64 or MSVC, Winsock2 Linux: GCC/Clang, pthread, libdl
# Windows
gcc server.c -o server.exe -lws2_32
# Linux
gcc server.c -o server -lpthread -ldl -Wall -O2# Windows
server.exe
# Linux
./serverTest with: curl http://localhost:9090
Edit the constants in the code:
#define MAX_THREADS 10 // Simultaneous threads
#define CACHE_CAPACITY 100 // Cache entries
#define SERVER_PORT 9090 // Server port
#define MAX_PLUGINS 10 // Maximum pluginsmain()
└─> socket_server()
└─> connection_manager()
└─> distributed_request_processing()
├─> LRU Cache
├─> Asynchronous Logger
├─> Load Balancer
└─> Plugins
void plugin_init(void* context) { }
void plugin_process(const char* data, void* context) { }Compile: gcc -shared -fPIC my_plugin.c -o my_plugin.so
__declspec(dllexport) void plugin_init(void* context) { }
__declspec(dllexport) void plugin_process(const char* data, void* context) { }Compile: gcc -shared my_plugin.c -o my_plugin.dll
Place the plugins in the ./plugins/ folder
Port in use (error 10013/EADDRINUSE):
# Windows
netstat -ano | findstr :9090
taskkill /PID <number> /F
# Linux
sudo lsof -i :9090
sudo kill <PID>Permission denied: Run as administrator or switch to a port > 1024
Concurrency: Threads, semaphores, mutexes, condition variables Networking: TCP sockets, basic HTTP protocol Architecture: LRU cache, producer-consumer, plugin system, load balancing Systems: Dynamic loading, signal handling, asynchronous file I/O
| Feature | Windows | Linux |
|---|---|---|
| Threads | CreateThread | pthread_create |
| Mutex | CRITICAL_SECTION | pthread_mutex_t |
| Semaphore | CreateSemaphore | sem_t |
| Sockets | Winsock2 | POSIX sockets |
| Plugins | LoadLibrary (.dll) | dlopen (.so) |
- Requests/second: ~5000–10000
- Average latency: <1ms
- Simultaneous connections: 10 (MAX_THREADS)
- Memory usage: ~5–10 MB base
Educational project demonstrating advanced techniques. For production use, add robust error handling, HTTPS, authentication, and rate limiting.
MIT License – Free for use and modification.