Skip to content

Simple TCP servers made in pure C. Implements select, poll and epoll strategies. Includes clients for simulations.

Notifications You must be signed in to change notification settings

lzcampos/c-tcp-server-and-client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

C Networking Examples: single and multiple-client servers

This repository contains small, focused examples of TCP networking in C:

  • Multiple-client echo servers implemented using:
    • select(2) → binary server-select
    • poll(2) → binary server-poll
    • epoll(7) → binary server-epoll
  • Clients
    • client → single connection, sends multiple requests over one TCP connection
    • multiple-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.

Build (Linux/Manjaro)

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 binaries

Optionally, you can also build the single-connection demo server:

make server-single  # builds 'server-single' (demo, not part of 'make all')

Run

  1. Start a server (pick one):
./server-select
# or:
./server-poll
# or:
./server-epoll

They listen on port 9090.

  1. Run the single-connection client:
./client [server_ip] [port] [num_requests]
# defaults: 127.0.0.1 9090 3

Example:

./client 127.0.0.1 9090 5
  1. Run the multi-connection client:
./multiple-client [server_ip] [port] [num_requests_per_client] [num_clients]
# defaults: 127.0.0.1 9090 3 10

Example:

./multiple-client 127.0.0.1 9090 2 20
  1. (Optional) Single-connection demo server:
./server-single [port]
# defaults to port 9090 if omitted

Notes

  • 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 SIGPIPE and handle SIGINT/SIGTERM for graceful shutdown.

About

Simple TCP servers made in pure C. Implements select, poll and epoll strategies. Includes clients for simulations.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published