Skip to content

GeorgeGrasu/TCP-UDP-Protocol-Implementation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TCP/UDP Protocol Implementation

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.

Features

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

Architecture

  • 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/unsubscribe commands via stdin while listening for incoming messages.
  • helpers.h: Contains common includes, macros (like DIE for error handling), and protocol constants.
  • Makefile: Script to compile the project.

Build

To compile both the server and the subscriber:

make

To clean up the executables:

make clean

Usage

1. Run the Server

Start the server on a specific port.

./server <PORT>

Example:

./server 12345

2. Run the Subscriber

Start 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 12345

3. Subscriber Commands

Once 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
  • Unsubscribe from a topic:

    unsubscribe <topic>
    
  • Exit:

    exit
    

    (Or simply close the server/subscriber with Ctrl+C, though strictly exit is the command).

About

This C++ Server-Client application efficiently routes UDP messages to TCP subscribers using I/O multiplexing with poll. Key features include robust binary protocol parsing (Int, Float, String) and advanced Wildcard subscription logic (+, *). It ensures low-latency delivery, real-time feedback, and full compliance with the assignment protocol.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors