A frame has the following fields: info seq ack A packet contains that data to be put in the info field of a frame. getNextData gets a packet of data from the network layer send sends a frame over the network handleData processes the data Sender: int nextToSend; // either 0 or 1 frame s; packet buffer; event_t event; nextToSend = 0; getNextData(&buffer); while(1) { s.info = buffer; s.seq = nextToSend; send(&s); startTimer(); waitForEvent(&event); // frame arrival, checksum error, or timeout if (event == frameArrival) { // ack getFrame(&s); if (s.ack == nextFrameToSend) { getNextData(&buffer); nextToSend = 1 - nextToSend; } } } Receiver: int frameExpected; / either 0 or 1 frame r,s; event_t event; frameExpected = 0; while(1) { waitForEvent(&event); // frame arrival or checksum error if (event == frameArrival) { getFrame(&r); if (r.seq == frameExpected) { handleData(&r.info); frameExpected = 1 - frameExpected; } s.ack = 1 - frameExpected; send(&s); } } Notes: The sender sends a frame when it times out or gets something. We assume that the sender's waitForEvent stops the timer. The sender takes the same action on timeout or checksum error. The sender always sends a frame when an event occurs. Why does the sender resend the next frame when it receives a duplicate ack? Because it stopped the timer and cannot now time out for this frame. The receiver sends an ack whenever it get a frame. Why does the receiver send an ack when it receives a duplicate frame? Beacuse the ack may have gotten lost.