This project implements a client-server application for message distribution. It consists of a Server that receives messages via UDP and forwards them to active TCP Subscribers based on topic subscriptions.
- I/O Multiplexing: Both Server and Subscriber use
poll()for efficient handling of multiple connections and input sources. - UDP Protocol Parsing: The server parses binary UDP payloads containing various data types:
INT(Integer)SHORT_REAL(Short Real, 2 decimals)FLOAT(Float, variable precision)STRING(Text)
- Wildcard Subscriptions:
+: Matches exactly one hierarchy level (e.g.,upb/+/temperature).*: Matches zero or more hierarchy levels (e.g.,upb/precis/*).
- TCP Client Feedback: Subscribers receive and display messages in real-time and provide local feedback for subscription commands.
- server.cpp: Manages the UDP socket, TCP listener, and all connected clients. It stores subscriptions and routes incoming UDP messages to the matching TCP clients.
- subscriber.cpp: Connects to the server, sends its ID, and allows the user to issue
subscribe/unsubscribecommands via stdin while listening for incoming messages. - helpers.h: Contains common includes, macros (like
DIEfor error handling), and protocol constants. - Makefile: Script to compile the project.
To compile both the server and the subscriber:
makeTo clean up the executables:
make cleanStart the server on a specific port.
./server <PORT>Example:
./server 12345Start a subscriber with a unique ID, connecting to the server's IP and Port.
./subscriber <ID_CLIENT> <IP_SERVER> <PORT_SERVER>Example:
./subscriber C1 127.0.0.1 12345Once the subscriber is running, you can use the following commands in its terminal:
-
Subscribe to a topic:
subscribe <topic>- Example:
subscribe upb/precis/temperature - Example (Wildcard):
subscribe upb/+/temperature
- Example:
-
Unsubscribe from a topic:
unsubscribe <topic> -
Exit:
exit(Or simply close the server/subscriber with
Ctrl+C, though strictlyexitis the command).