If part of an Irish Rail update arrives late, how does it still read in order?
An Irish Rail update reaches your phone in pieces. The last piece gets there before the middle one. When you read the update, the words are still in the right order. How does your phone know where each piece belongs?
Your phone is the client. It uses HTTP to request a web page. Routers forward the request in IP packets using destination addresses. The web server sends the page back. On the way back, IP packets can arrive out of order. The Web uses the Internet to carry those packets.
Each letter here takes one byte. A L arrives first, but it belongs at positions forty-two and forty-three. G O arrives later and belongs at forty and forty-one, so it goes before A L. For each of these data segments, TCP calls the first byte’s number the sequence number.
A TCP segment starts at byte seventy and carries three bytes. The next segment starts immediately after those bytes in the stream. What sequence number should that next segment carry? Pick an answer.
You’re expecting byte fifty. Bytes fifty and fifty-one arrive, but fifty-two is missing. The receiver sends acknowledgement fifty-two. Even when fifty-three and fifty-four arrive and wait in the buffer, the acknowledgement stays at fifty-two. It gives the next byte needed to continue the unbroken stream.
At the sender, the timer expires while some bytes are still unacknowledged. The sender resends the earliest unacknowledged data with the same byte numbers. If those bytes arrive, they can fill the gap. Sending data again like this is called retransmission.
The sender sends R A I, L, then W A Y. R A I arrives first, so acknowledge one hundred and three. W A Y arrives next and waits. After a timeout, the sender resends L at one hundred and three. Now read RAILWAY and acknowledge one hundred and seven.
SUN starts at byte twenty. E T arrives next at byte twenty-four and waits in the buffer. Then the missing S is resent and arrives at byte twenty-three. Pick the option that gives both the reassembled stream and the final acknowledgement number.
The highest byte you’ve seen is one hundred and six. If you use that to send acknowledgement one hundred and seven, you’re claiming all earlier bytes arrived. Find the first gap instead. Keep the acknowledgement at one hundred and three until that byte arrives.
If asked to compare TCP and IP, explain that TCP provides reliable, ordered delivery using byte numbers, acknowledgements and retransmission. IP provides addressing, and routers use it to forward packets. For a web response sent over TCP, TCP keeps the bytes in order. IP also carries voice packets in voice over IP calls.