A lightweight TCP server implementation in C++ that demonstrates basic socket programming concepts.
This project implements a simple TCP server that accepts client connections, receives client messages, and echoes them back to the client. This program was built to learn and explore fundamental networking concepts in C++.
- Single client connection support
- Message echo functionality
- Client disconnection handling
- Error handling for socket operations
- Simple command-line interface
Compile the server using: g++ -std=c++17 server.cpp -o server
- Start the server by specifying a port number: ./server <port#>
- If you receive an error immediately, check if the port is already in use: lsof -i :<port#>
- Once the server is running, open a new terminal and connect using netcat: nc localhost <port#>
- Type messages and press Enter to send them. The server will echo back your messages.
- To disconnect, press Ctrl+C in the client terminal. The server will display a disconnection message and close the socket.
This program was heavily inspired by Benedikt Thordarson c++ tutorial on basic TCP server. Watch his video explaining this program to learn more!