Skip to content

Corg-Labs/TCP

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

relay

Multi-client TCP chat server in C, built on select() — no threads, no libraries.

A small, self-contained demo written in pure C — just the standard library and POSIX sockets. Part of the Corg-Labs collection of single-file C programs.


How It Works

  1. One listening socket accepts many clients on a single port
  2. A single select() loop multiplexes the listener and every client — one thread total
  3. Anything one client sends is relayed (broadcast) to all the others
  4. A live dashboard redraws on each event, showing every client's name, IP, port and message count

Build

gcc relay.c -o relay

Run

./relay 8080

Then connect from one or more other terminals:

nc localhost 8080

Commands

Once connected, just type to chat. Special commands:

  • /nick NAME — change your display name

Every line you send shows up as [yourname] message in everyone else's terminal, and join/leave notices are broadcast automatically.

Notes

  1. Handles up to 32 simultaneous clients (raise MAX to allow more)
  2. SO_REUSEADDR lets you restart the server immediately without "address in use"
  3. Blank lines are ignored so stray newlines don't spam the room
  4. Press Ctrl-C to stop the server

About

► TCP relay / echo server in C.

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages