Overview
TheReliableClientProtocol class provides client-side implementation of the Selective Repeat ARQ protocol over UDP. It handles connection establishment via three-way handshake, reliable data transmission with windowing, and automatic retransmission of lost packets.
Connection Establishment
connection()
Establishes a three-way handshake connection with the server.The UDP socket to use for communication
The server’s address and port number
The server’s data port assigned for this connection
The connection process implements a three-way handshake:
- Client sends SYN packet (type=2)
- Server responds with SYN-ACK (type=3)
- Client sends ACK (type=1)
Data Transmission
requestresponse()
Sends data reliably to the server and waits for a response using the Selective Repeat protocol.The UDP socket for communication
The server’s data port address
The data payload to send to the server
The complete response received from the server
How it works
How it works
The method automatically:
- Fragments data into 1013-byte chunks
- Sends the total packet count first
- Transmits packets using a sliding window (size: 100)
- Handles ACKs and retransmits on timeout or NACK
- Receives the server’s response using the same protocol
Internal Methods
sendreq()
Handles the sliding window transmission logic with selective repeat.Total number of data packets to send
Destination server address
Socket for transmission
List of data chunks to send
isAcked()
Timeout handler that checks if a packet has been acknowledged and retransmits if necessary.Sequence number of the packet to check
Socket for retransmission
Current retry attempt count
Packets are retransmitted up to 10 times before being abandoned.
response()
Waits for and receives the complete response from the server.The assembled response data from all received packets
getRequestFromPacket()
Receives and assembles packets using the Selective Repeat protocol.Socket to receive packets from
Expected number of packets to receive
The complete assembled data from all packets
Protocol Constants
Error Handling
Socket Timeout
Socket Timeout
When waiting for ACKs, the socket uses a 50ms timeout. On timeout, the size packet is retransmitted.
Lost Packets
Lost Packets
The protocol handles packet loss through:
- Cumulative ACKs for in-order packets
- NACKs (type=4) for out-of-order packets
- Timeout-based retransmission with exponential backoff
Connection Closure
Connection Closure
When a packet with type=6 is received, the connection is closed gracefully.
Example Usage
See Also
ServerTcpProtocl
Server-side protocol implementation
Packet Format
Packet structure and builder pattern