Skip to content

A simple multi-client chat application using POSIX threads, TCP/IP sockets, and standard IPC mechanisms.

Notifications You must be signed in to change notification settings

Brunomvsilva/TCP-Group-Chat

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TCP_GroupChat

A simple multi-client chat application using POSIX threads, TCP/IP sockets, and standard IPC mechanisms.


Overview

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.

Features

  • 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.

Build Instructions

Navigate to the project folder:

cd ~/TCP_GroupChat

Build all components:

make all

or build separately:

make client
make server

Clean build files:

make clean

Transfer compiled binaries to a remote host:

make transfer IP=<ip_address> DIR=<destination_path>

Directory Structure

TCP_GroupChat/
├── Makefile
├── README.md
├── tcpclient/
│   ├── Makefile
│   ├── client_recv.c
│   └── client_send.c
├── tcpserver/
│   ├── Makefile
│   └── server_main.c
└── utils/
    ├── parser.c
    └── parser.h

Running the System

1. Start the Server

Open the first terminal:

./tcpserver/server_main.elf 5000

The server listens on port 5000 for client connections.


2. Start the First Client

Open a second terminal:

./tcpclient/client_recv.elf 127.0.0.1 5000

This launches the client receiver daemon.


3. Start a Second Client

Open a third terminal:

./tcpclient/client_recv.elf 127.0.0.1 5000

Both clients are now connected to the same server.


4. Send Messages

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.


5. Read Pending Messages

To display any unread messages:

./tcpclient/client_send.elf

6. Disconnect a Client

To close a client connection:

./tcpclient/client_send.elf exit

7. Stop the Server

To stop the server:

  • Press CTRL + C, or
  • Type exit and press Enter.

Running on Multiple Machines

On the server machine:

hostname -I
./tcpserver/server_main.elf 5000

On 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.


Executables

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"

About

A simple multi-client chat application using POSIX threads, TCP/IP sockets, and standard IPC mechanisms.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published