Go-Back-N
GBN is a sliding‑window reliable protocol. The sender can have several packets “in flight,” and the receiver only accepts the next expected packet. Anything out of order is ignored, and the receiver keeps sending the same ACK for the next expected sequence number.
Sender
Think of the sender loop like this:
- Slice the input file into fixed‑size payloads.
- Keep a window of packets you’ve sent but not yet confirmed.
- If there is room in the window, send the next packet.
- If an ACK comes back that moves the window forward, slide the window.
- Receiver always send ACK for the next expected packet’s sequence number.
- If you wait too long with no progress, resend everything in the current window.
- When all data is confirmed, finish with a clean close (FIN/FINACK).
The main idea is “cumulative ACKs + one timer + resend the window on timeout.”
Receiver
The receiver is simpler:
- If a packet is exactly the next expected sequence number, accept it and write it.
- Otherwise, discard it.
- Always send ACK for the next expected sequence number (even for duplicates).
- When you see FIN, respond with FINACK and close.