This repository contains small, focused examples of TCP networking in C:
- Multiple-client echo servers implemented using:
select(2)→ binaryserver-selectpoll(2)→ binaryserver-pollepoll(7)→ binaryserver-epoll
- Clients
client→ single connection, sends multiple requests over one TCP connectionmultiple-client→ spins up multiple connections to the server and sends requests
Servers listen on 0.0.0.0:9090. Clients default to 127.0.0.1:9090.
The clients enable TCP keep-alive and read one response per request.
make # builds: server-select, server-poll, server-epoll, client, multiple-client
make servers # builds only the servers
make clients # builds only the clients
make clean # removes all built binariesOptionally, you can also build the single-connection demo server:
make server-single # builds 'server-single' (demo, not part of 'make all')- Start a server (pick one):
./server-select
# or:
./server-poll
# or:
./server-epollThey listen on port 9090.
- Run the single-connection client:
./client [server_ip] [port] [num_requests]
# defaults: 127.0.0.1 9090 3Example:
./client 127.0.0.1 9090 5- Run the multi-connection client:
./multiple-client [server_ip] [port] [num_requests_per_client] [num_clients]
# defaults: 127.0.0.1 9090 3 10Example:
./multiple-client 127.0.0.1 9090 2 20- (Optional) Single-connection demo server:
./server-single [port]
# defaults to port 9090 if omitted- All code uses only POSIX/Linux sockets, no external libraries.
- The echo servers read from each client and write the same data back.
- Clients ignore
SIGPIPEand handleSIGINT/SIGTERMfor graceful shutdown.