Reliable User Datagram Protocol RUDP (original) (raw)

Last Updated : 15 Oct, 2025

Reliable UDP (RUDP) is a protocol built on top of UDP that adds reliability features like acknowledgments, retransmissions and ordered delivery - all while keeping UDP’s low-latency benefits. When it comes to sending data across the internet, we often face a trade-off between speed and reliability.

**Note: Think of it as "UDP + reliability layer", making it suitable for high-speed, real-time applications (like gaming, streaming and VoIP) that can’t afford TCP’s connection overhead but still need dependable delivery.

Why UDP Alone Isn’t Enough

UDP sends data packets (called datagrams) directly from sender to receiver without any handshake or confirmation. This means:

**Note: RUDP fixes these issues by introducing a reliability layer on top of UDP - a smart middle ground.

RUDP Architecture - How It Works

RUDP sits in the application layer, built over UDP. Both the sender and receiver maintain a window of packets - a fixed-size range that controls how many packets can be sent or received at a time. Here’s how it flows:

RUDP-Protocol-Architecture

RUDP Protocol Architecture

  1. Sender breaks the message into smaller segments.
  2. Each segment is assigned a sequence number and checksum (to verify data integrity).
  3. Packets are sent through the RUDP protocol over UDP.
  4. The receiver checks for errors and order, sends ACKs (acknowledgments) and buffers packets until all are received correctly.
  5. If an ACK isn’t received within a timeout, the sender retransmits that packet.

**Note: This system ensures reliability - but without TCP’s heavy connection setup.

Key Components of RUDP

1. Thread-Safe Buffers

Both sender and receiver use synchronized shared buffers protected by semaphores to prevent multiple threads from accessing data simultaneously - avoiding deadlocks and corruption.

2. Window Management

Two important counters manage the flow:

**Note: This allows efficient tracking of which packets are "in-flight" and which are confirmed.

3. Timeout and Retransmission

4. Network Simulation & Queuing

Sliding Window Protocol - The Core of RUDP Reliability

The Sliding Window Protocol (SWP) is the heart of RUDP. It ensures that:

Types:

  1. One-Bit Sliding Window Protocol – simplest, only one packet in transit.
  2. Go-Back-N Protocol – retransmits all packets after a loss.
  3. Selective Repeat Protocol – retransmits only the lost packet (most efficient, used in RUDP).

Piggybacking Technique

Mathematical View of Window Updates

Internal Classes in RUDP

Class Purpose
RUDP Core class managing send/receive, window setup and timer control.
Buffer_RUDP Shared buffer with thread-safe access (semaphores).
Thread_Receiver Thread that listens for incoming packets and ACKs simultaneously.
Segment_RUDP Defines structure for RUDP packets (sequence number, checksum, etc.).
Timeout_Handler Handles retransmissions when ACKs are delayed or lost.
Support_RUDP Handles network-level tasks like sending UDP packets, simulating delay/loss.
Client/Server Interfaces for sending and receiving data using the RUDP layer.

RUDP Work Flow

Client Side

Receiver-Side-Code-Architectur

Client Side Code Architecture

  1. Data is divided into segments.
  2. Each segment gets a frame (sequence number + checksum).
  3. Sent using Support_RUDP.send_udp().
  4. Timer starts for each segment.
  5. If ACK is received - mark as delivered.
  6. If timeout occurs - resend packet.

Server Side

Server-Side-Code-Architecture

Server-Side Code Architecture

  1. Listens for incoming packets.
  2. Validates checksum and sequence number.
  3. Sends ACK for each valid packet.
  4. Reorders any out-of-sequence packets.
  5. Delivers final data to the application once all are received.

Pseudo Code for RUDP Class

Class RUDP{
//setting up the window sizes
set Receiver Window size
set Sender Window size
start receiver thread that receives the aka(Acknowledgment) and data for both the receiver and the sender
//sender calls
sent_data(byte[] data_gram, int size)
{
//process flow => data -> segments -> store into sender buffer -> send -> start timer
//breaking into segments and sending along with frames
Divide into the segments.
put every segment into the sender's buffer
segment sending using sent_udp() of support_RUDP class
timeout scheduling for the data that is divided into segments using frames
}
//receiver calls
receive_data(byte[] buffer, int size)
{
//receiving of the segments of the data packets
segment receiving once at a time including the frames
}
//call by both the sender and receiver
close()
{
//creation of flag for the indication
creation of a flag segment to indicate the data transfer status
//verification of the data
//if data receiving completed -> close
once the complete data is received close the segment
}
}
//RUDP class ends here

Pseudo Code of Thread_receiver Class

Class Thread_receiver
{
while(true)
{
//waiting for the packet -> received
Receive the packet from socket
//numberize or make checksum of the data
individualize a segment from the packet that is received
//verification of the data
checksum verification that is sent along the frames
if segment contains acknowledgment
process -> remove segments from the sender's buffer
if segment contains data
put data->receiver's buffer
send acknowledgment
}
}
//end of Thread_receiver Class

Pseudo Code for Support_RUDP Class

Class Support_RUDP
{
//simulate over the conditions that can cause the segments not received completely
random network delay
network loss
any other potential that can effect the packet
//process
packets from the segments received processing
//sent
sent the data packet over the socket
}
//end of Support_RUDP class

**Pseudo Code for Client-Server Class
//Sender
Class Client{
RUDP rudp = new RUDP(Host_name, Port, Local);
//send the data
rudp.send();
//close
rudp.close();
}
//client class end
//Receiver Class start
Class Server{
RUDP rudp = new RUDP(Host_name, Port, Local);
//receive the data
rudp.receive();
//close
rudp.close();
}

Use Cases of RUDP

RUDP vs UDP vs TCP

Feature UDP TCP RUDP
Connection setup No Yes (3-way handshake) No
Reliability No Yes Yes
Acknowledgment No Yes Yes
Packet ordering Not guaranteed Guaranteed Guaranteed
Speed Very fast Moderate Near UDP speed
Use cases Streaming, gaming File transfer, web Real-time reliable systems