This project demonstrates a simple TCP server-client communication using C. The server and client can exchange messages over a specified port, making it an ideal example for understanding basic socket programming.
- Features
- Requirements
- Usage
- Compilation
- Running the Server
- Running the Client
- Error Handling
- License
- Simple TCP server that listens for client connections.
- Client connects to the server and exchanges messages.
- Basic error handling for socket operations.
- Communication using the
select()
function for asynchronous handling.
- GCC compiler
- Unix-based operating system (Linux, macOS) (will work on Windows with Unix environment setup too)
- Basic knowledge of C Programming.
- Compile the server and client programs.
- Run the server and client on the same or different machines.
- Specify the hostname and port for the client to connect to the server.
gcc -o server server.c
gcc -o client client.c
Start the server by specifying a port number:
./server [port]
Start the server by specifying the hostname and same port number as the server:
./client [hostname] [port]
- The server and client programs use the
error
function to print error messages and terminate the program when a critical error occurs. - Proper error handling ensures that issues such as failed socket creation, binding, and connection attempts are reported.
This project is open source and available under the MIT License.