Linux Socket Chat
A simple chat application with client-server architecture, written in C++ using linux socket programming and multithreading
Overview
- One server, multiple clients
- Clients can connect to the server and either send connection request to other free clients or wait and accept a connection request
- One mutex mapped to each client
- While attempting to connect with another client, the connecting client acquires its own mutex and then the other client's to ensure that concurrency issues are handled well while connecting
- Paired clients release the acquired mutex on disconnecting
Setup and use locally
- Clone the repo and change directory
cd linux-socket-chat
- Compile the
server.cpp
andclient.cpp
files
g++ server.cpp -o server -lpthread
g++ client.cpp -o client -lpthread
- Run the server
./server
- Run the clients
./client
Commands
Command |
Use |
menu | show list of supported commands |
stats | show list of clients with their FDs and status { FREE, BUSY } |
connect *CLIENT_FD* | pair with (connect to) client identified by CLIENT_FD |
goodbye | unpair with a connected client |
close | disconnect from server |