A publish-subscribe messaging system with a centralized coordinator, built in C++ using TCP sockets. Participants register with the coordinator and can send messages to all other active participants, with support for disconnect/reconnect and message expiration.
- Centralized coordinator: Manages participant registration and message routing
- Publish-subscribe model: Messages sent by any participant are broadcast to all others
- Message expiration (TTL): Messages expire after a configurable time-to-live duration; expired messages are not delivered on reconnect
- Fault tolerance: Participants can disconnect and reconnect, receiving any missed messages that have not yet expired
- Dual-socket architecture: Separate command and message sockets per participant
- Thread pool concurrency: Both coordinator and participants use thread pools for handling concurrent connections and message delivery
- Message logging: Participants log received messages to a local file
coordinator-- Central server that accepts participant connections. Maintains a registry of active participants and their message file descriptors. When a participant sends a message, the coordinator broadcasts it to all other connected participants. Tracks which participants have received each message for reliable reconnect delivery.participant-- Connects to the coordinator and provides an interactive command prompt. Opens a listening socket for receiving messages from the coordinator.
Participants send #-delimited messages to the coordinator over the command socket: <id>#<command> [args]#<ip>. The coordinator parses these and dispatches to the appropriate handler (register, deregister, disconnect, reconnect, msend).
make # builds both coordinator and participant
make clean # removes binaries and build artifactsRequires a C++ compiler with C++20 support and pthreads.
-
Start the coordinator:
./coordinator config/coordinator.txt
-
In separate terminals, start participants:
./participant config/participant1.txt ./participant config/participant2.txt
-
On each participant, register with the coordinator:
participant> register <listen_port> -
Send messages:
participant> msend Hello everyone -
Other commands:
disconnect-- Disconnect from the group (can reconnect later)reconnect <listen_port>-- Rejoin and receive missed non-expired messagesderegister-- Permanently leave the group
Coordinator config (config/coordinator.txt):
<port>
<message_ttl_seconds>
Participant config (config/participant1.txt):
<participant_id>
<log_file_name>
<coordinator_ip> <coordinator_port>