Skip to content
Related Articles

Related Articles

Reliable User Datagram Protocol (RUDP)

View Discussion
Improve Article
Save Article
  • Last Updated : 31 May, 2022

RUDP stands for Reliable user datagram protocol, whereas UDP is one of the core members of IP i.e internet protocol suite. UDP is used as a highly time-sensitive communicative protocol. R in RUDP stands for Reliable, it is a UDP-based data transfer but with higher Reliability. It provides reliability by using the sliding window protocol. RUDP is basically the solution to the UDP where data reliability along with confirmation is needed.

As UDP provides unreliable data transfer protocol which is unreliable services of things and the worst it sometimes goes missing without notice. Reliable UDP uses both positive and negative feedback to provide data reliability which provides reliable data transfer.

In UDP sender’s simply send a message without a piece of prior information about the receiver’s availability which results in a faster rate but it can result in the loss of some packages, also the receiver can receive duplicate packets and UDP also does not provide information that the package has been received or not. RUDP used a sliding window protocol that delivers or transfers the datagram with reliability.

RUDP Architecture 

The sending process and receiving process of the architecture both stand in the application layer. The sender server sends the data packets to the receiving channel using RUDP protocol; a window size is maintained by both the sender and the receiver, the window consists of some predefined value tending to maximum avoiding the communication errors taking all the edge cases where the packets can be dropped. 

RUDP Protocol Architecture

RUDP Protocol Architecture

Implementation of RUDP protocol:

Use synchronized shared buffers using counting semaphores so that only one thread access the buffer at a time to prevent the deadlock situation from occurring. 

Let’s keep two-variable called as the base and next to keep the track of the window functioning. If the sender sent’s the packet, the variable next is incremented to 1, this is the way of calculating the number of packets in the buffer.

The timeouts are handled using the timers which are scheduled immediately after sending the packet over the channel, simulate the packet loss rate and random network delay in the protocol.

packets are kept in a queue and assigned a value that values the system’s current time plus the network delay. When the current time of the system is associated with the assigned value the packet is freed from the queue and sent over the network. While the packet is sent over the network it gives an (ACK) acknowledgment. When the ack matches with the sequence number senders send another packet assigning it with the consecutive number.

Classes in RUDP Protocol:

Following are the classes that are used to implement the RUDP protocol:

  • RUDP: This contains the send() and receives () functions called by the client and server.
  • Buffer_RUDP: contains the implementation shared buffer using counting semaphores.
  • Receiver_Thread: Implements a threaded architecture that simultaneously waits for the packets in the sockets while sending and receiving the data and waits to process the incoming data.
  • Segment_RUDP: defines the structure of RUDP packets.
  • Timeout_Handler: to handle the timeouts
  • Support_RUDP: provides functions like send_UDP();
  • Client: It sends the data.
  • Server: It receives the data.

Sliding Window Protocol:

Sliding window protocol also known as RUDP’s SWP on which RUDP is based, is used where the reliability comes into play and it is very much essential or for security reasons where the knowledge of data transferred along with confirmation is required. It works in segments which means it divides the provided data into segments then packets or data packets are prepared and sent over the network, resulting in when the receiver receives the package it checks the order of the packets and discards duplicates and after that, is sent it sends the acknowledgment to the sender for the correctly received packets.

There are 3 Sliding window Protocols:

  • One Bit Sliding Window Protocol
  • Go back to N protocol
  • Selective Repeat Protocol

Piggy-backing Technique:

Sliding window Protocol uses the piggy-backing technique, the technique is based on the acknowledgment that is received but, how is received? So, the answer is it provides the sliding window protocol to attach the acknowledgment in the next frame so that when a receiver receives the data it maintains a set of sequence numbers which is corresponding to the frames that are also can be called acknowledgment frames within a window portion of same or different sizes.

The mathematics of frame calculation:

When a new packet is sent by the sender to the receiver it is given the highest packet sequence mark and the window’s upper edge is incremented with one for the acknowledged frames and vice versa for the unacknowledged frames. That calculates the mark of unacknowledged frames as well as acknowledged frames and when this number comes to zero that means all the packets have been delivered successfully and it provides feedback to the sender. It is used in data-intensive applications that require a lot of work in a very less amount of time over high-speed networks, where reliability plays a very important role.

Server-Side Code Architecture:

  • Client Class sets the rate of loss and sends the data to the RUDP class, where window sizes of both the sender and receiver are set in the class.
  • The RUDP class as per the working divides the data into segments of equal sizes and hence assigns the frames i.e. sequence number and checksum to each segment separately then put it in the sender’s window if it has any available slot.
  • Support_RUDP comes into play now, when the data packets in segments are sent by the sender this class collects and prepares the packets from the segments and sends them over the unreliable channel. Once it is sent the timer goes on immediately.
  • Thread_receiver class is the important class for the RUDP structure it provides a thread along with the thread of the data it parallelly sends a thread with the data and waits on the socket for the incoming data, when it receives the packet from the socket it makes a segment and verifies the checksum, if the checksum clarifies it is the sent data then it checks for the acknowledgment if the acknowledgment received then it removes the packet from sender’s window and sent it over the socket; if a timeout happens and a packet is lost it resends the packet and restart the timer immediately, If the RUDP class receives the packet before the timeout then it cancels the timer.
Server-Side Code Architecture:

Server-Side Code Architecture:

Receiver Side Code Architecture:

  • Thread_receiver Class that implemented a thread parallel runs with the thread of the sent data and one of the instances waits at the socket to continue to process the data that is coming. Once the class receives the packet is verified with the segment and made a segment from it and matches with the checksum. If the segment contains the required data then it sends an acknowledgment and puts it in the Buffer_receiver class and if the packet is not there then it stores all following the lost into the Buffer_receiver.
  • Once the lost packet is received it processes all and then the RUDP class delivers all the packets reordering correctly once it was buffered to the server.
  • Once the confirmation is provided that all the data have been received then the connection is closed.
Receiver Side Code Architecture:

Receiver Side Code Architecture:

PseudoCode 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 fromt he 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();
}

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!