This is a basic single-threaded TCP server with an event loop using the poll system call, written in C, without any third-party library, solely relying on native C functionalities. The server listens on a port and echoes back received data. I've also written a simple client to test the server.
I've followed the tutorial at Beej's Guide to Network Programming to gain an understanding of sockets before writing this server. I followed The Event Loop Implementation to understand how to implement an event loop using poll
. I also watched Johannes 4GNU_Linux's YouTube video to understand how to implement a simple event loop in C.
-
Clone the repository
-
Compile client and server programs (don't worry, there's a Makefile to do this for you)
make
-
Run the server (it will run on port 3000)
./bin/server
-
Run the client in another terminal
./bin/client
-
Type something in the client terminal and press enter. You should see the server echoing back what you typed.
-
Ctrl+C to stop the server and client.
Resources: