This project is a UDP-based chat system written in C++.
It provides a lightweight server and client that communicate over UDP sockets while experimenting with reliability mechanisms such as acknowledgments (ACKs).
-
Server
- Creates a UDP socket and binds to a given IP/port.
- Receives
MessagePacketandAckPacketstructures from clients. - Tracks connected clients (
client_list). - Broadcasts messages to all clients except the sender.
- Immediately sends ACKs back to the message sender.
- Runs a dedicated packet listener thread (
RegisterReceiver).
-
Client
- Connects to the server using UDP.
- Sends an initial handshake (null byte) for registration.
- Listens for incoming messages in a background thread.
- Prints server-broadcasted messages.
- Sends messages typed by the user.
- Implements ACK sending when receiving
MessagePackets.
- Full reliable ACK system to guarantee delivery.
- Queueing and splitting long messages (
addToQueue+mheaderintegration). - Decoder for handling structured input before sending packets.
- Better buffer and error handling.
- More robust client management (timeouts, disconnects).
struct MessagePacket {
uint32_t type; // MESSAGE
uint32_t seq; // Sequence number
uint32_t size; // Payload size
char data[256]; // Message
};
struct AckPacket {
uint32_t type; // ACK
uint32_t seq; // Sequence number being acknowledged
};Requirements Linux / Unix-like environment
GNU Make
g++ (C++17 or later)
POSIX sockets (arpa/inet.h, netinet/in.h, sys/socket.h)
Build From the repo root, simply run:
makeThis builds both the server (udp_server) and the client (udp_client).
To build them separately:
make udp_server
make udp_clientTo clean build artifacts:
make clean- Run server Start the server:
./udp_server- Run one or more clients:
./udp_clientClients can now send messages, which the server broadcasts to all connected clients (excluding the sender).
.
├── client.cpp
├── server.cpp
├── mheader/
│ └── mheader.h
│ └── mheader_encoder.cpp
└── Makefile