Multi-threaded TCP Client/Server implementation in C++
The purpose of this project is to familiarise with socket programming in modern C++17 syntax, by utilizing the standard thread/mutex libraries to manage concurrency and synchronization with conditional variables.
TCP is a reliable protocol that guarantees that the data remain intact and arrive in the same order in which they were sent. While, multithreading allows multiple clients to connect and interact with the server in tandem, without significant drop-offs in transmission time.
-
The Client connects and requests a specific directory from the Server. Then, it receives each file along with its information, so that it can locally replicate the same folder hierarchy.
-
The Server creates two kinds of threads to handle the requests. The communication threads that are responsible for each client and the worker threads that send the respective files.
Ensure that you have Clang ver. >17.0 installed locally. For MacOS users, see this StackOverflow post on how to set up Clang-Tidy and other Clang toolings.
Also ensure that you have VSCode installed with all of the recommended extensions. Then, clone this repository. From the root directory of the project, run the following commands on the terminal:
# To build the project via CMake
# Step 1:
cmake -B build -S . # default, with no compiler flags
cmake -S . -B build -G "MinGW Makefiles" -DCMAKE_C_COMPILER="C:\msys64\ucrt64\bin\clang.exe" -DCMAKE_CXX_COMPILER="C:\msys64\ucrt64\bin\clang++.exe" # for Win32 using MinGW generator and MSYS2 Clang compiler
# Step 2:
cmake --build build
# In one terminal, spin up the server instance:
# ./build/server [-p <PORT>] [-s <THREAD POOL SIZE>] [-q <QUEUE SIZE>] [-b <BLOCK SIZE>]
./build/server -p 8080 -s 4 -q 10 -b 1024 # values specified here are by default
# In separate terminal(s), spin up client instance(s):
# ./build/client [-i <SERVER IP>] [-p <SERVER PORT>] [-d <FILE DIRECTORY>]
./build/client -i localhost -p 8080 -d . # values specified here are by defaultTo delete all the executable and object files generated:
rm -rf build
mkdir buildTo run clang-tidy:
# clang-tidy [-p build] <source-file>
clang-tidy server/server.cppThis project is largely based off of the work of this GitHub repository. The code has since been largely formatted for modern C++17 syntax and built using CMake.
