Skip to content

This project is a TCP/IP echo server wrote in C. The client sends a message to the server and the server echos back the message to the client.

Notifications You must be signed in to change notification settings

efriel94/tcp-echo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

49 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Synchronous TCP/IP Echo Server in C

This project is a synchronous TCP/IP echo server wrote in C which supports multiple clients. The client sends a message to the server and the server echos back the message to the client. The maximum amount of clients allowed to communicate with the server is defined in FD_SETSIZE

The synchronous I/O functionality was implemented using the functions in the select library. The server handles each client using file descriptors. Each client will have their own file descriptor which describes their socket address structure and each one is stored in fd_set on the server to keep track of the connections.
The server will continously loop around fd_set to handle new and existing client connections.

Adding new clients to the server: If the file descriptor being ready to be read in is the same as the master socket then it signifies that a new client is connecting to the server and so the new client will be added to fd_set
Handling existing clients: If the file descriptor being ready to be read in is not the same as the master socket then the server will handle the existing client within fd_set
Removing clients: If the return value from the received client is zero, then the server will close the client socket and remove their file descriptor from fd_set

Build

git clone https://github.com/efriel94/tcp-echo.git
cd tcp-echo
mkdir build && cd build && cmake ..
make

Usage

Run server first:

./server <port>

Clients:

./client <server-address> <server-port>

Demo

screen-gif

About

This project is a TCP/IP echo server wrote in C. The client sends a message to the server and the server echos back the message to the client.

Resources

Stars

Watchers

Forks

Packages

No packages published