A simple multi-client chat application using POSIX threads, TCP/IP sockets, and standard IPC mechanisms.
The system consists of three main components:
- Server – Handles client connections, message routing, and broadcast.
- Client Receiver – Runs as a background daemon, maintaining a TCP connection with the server and exchanging data through message queues.
- Client Sender – Communicates with the receiver via message queues to send or read messages.
- Supports multiple clients connected simultaneously.
- Each client is identified by a hostname and ID.
- Messages are broadcast to all active clients.
- Clients automatically switch to AFK if inactive.
- The server periodically checks each client's status.
- Internal communication uses POSIX message queues.
Navigate to the project folder:
cd ~/TCP_GroupChatBuild all components:
make allor build separately:
make client
make serverClean build files:
make cleanTransfer compiled binaries to a remote host:
make transfer IP=<ip_address> DIR=<destination_path>TCP_GroupChat/
├── Makefile
├── README.md
├── tcpclient/
│ ├── Makefile
│ ├── client_recv.c
│ └── client_send.c
├── tcpserver/
│ ├── Makefile
│ └── server_main.c
└── utils/
├── parser.c
└── parser.h
Open the first terminal:
./tcpserver/server_main.elf 5000The server listens on port 5000 for client connections.
Open a second terminal:
./tcpclient/client_recv.elf 127.0.0.1 5000This launches the client receiver daemon.
Open a third terminal:
./tcpclient/client_recv.elf 127.0.0.1 5000Both clients are now connected to the same server.
Each client uses the sender tool.
Client 1:
./tcpclient/client_send.elf "Hello from Client 1"Client 2:
./tcpclient/client_send.elf "Hi Client 1"The server broadcasts messages to all connected clients.
To display any unread messages:
./tcpclient/client_send.elfTo close a client connection:
./tcpclient/client_send.elf exitTo stop the server:
- Press
CTRL + C, or - Type
exitand press Enter.
On the server machine:
hostname -I
./tcpserver/server_main.elf 5000On each client machine:
./tcpclient/client_recv.elf <server_IP> 5000
./tcpclient/client_send.elf "message"Replace <server_IP> with the actual IP address of the server.
| Component | Path | Example Command |
|---|---|---|
| Server | tcpserver/server_main.elf |
./tcpserver/server_main.elf 5000 |
| Client Receiver | tcpclient/client_recv.elf |
./tcpclient/client_recv.elf 127.0.0.1 5000 |
| Client Sender | tcpclient/client_send.elf |
./tcpclient/client_send.elf "message" |