This project includes two C programs—a TCP server and client—that exchange text and return its reversal over a network connection.
Compile on any Linux system (e.g., Jason/Volta) or WSL:
gcc server.c -o server
gcc client.c -o clientOpen two terminals (or MobaXterm splits/tabs):
-
Start the server on port
5000:./server 5000
Expected output:
Server listening on port 5000 -
Run the client against the server:
./client 127.0.0.1 5000
- Enter your message (e.g.
Hello World) and press Enter. - Press
Ctrl+Dto signal end-of-input. - The client displays the reversed text and exits:
dlroW olleH Connection closed
Send data via a shell pipe:
echo "Hello World" | ./client 127.0.0.1 5000Prints reversed text immediately.
Server terminal:
$ ./server 5000
Server listening on port 5000
Client connected
Client disconnectedClient terminal:
$ echo "Hello World" | ./client 127.0.0.1 5000
dlroW olleH
Connection closed- Uses standard glibc—no external libraries needed.
- Ensure your port (e.g.,
5000) is free. - To connect across hosts, replace
127.0.0.1with the server’s IP address.