I have resolved the mystery of the handshakes. Three way handshake: SYN: -> Seq = x Ack = 0 (Ackflag = 0) SYN-ACK: <- Seq = y Ack = x+1 ACK: -> Seq = x+1 Ack = y+1 Now the first data byte in the -> direction will be number x+1, the first data byte in the <- direction will be number y+1. ------------------------------------------------------------------------ ``Four'' way handshake, in the simplest situation: FIN: -> Seq = x (the last byte I sent you was number x-1) Ack = y (if you have more to send, the next one I expect is y. The last one I got from you was number y-1.) A: Now there may be more ordinary Acks in the <- direction to acknowledge data that was not acknowledged yet. These are NOT part of the four-way handshake! The last one of these may have ``Ack = x'': ``I got everything up to byte number x-1. B: Special Ack <- Seq = y (Assuming no more data was sent in the <- direction.) Ack = x+1 (The complication: if you acknowledge a FIN, you increase Ack by one!) FIN: <- Seq = y Ack = x+1 Special ACK -> Seq = x+1 (Never send a lower Seq than the last Ack from the other side!) Ack = y+1 (If you acknowledge a FIN, you increase the Ack by one!) ----------------------------------------------------------------------- Complication: Sometimes the ``orinary Acks'' in ``A'' are not sent. Sometimes the ``Special Ack'' in ``B'' is not sent. If neither is there the ``four way handshake becomes: Abbreviated four way handshake: FIN: -> Seq = x Ack = y FIN: <- Seq = y Ack = x+1 ACK -> Seq = x+1 Ack = y+1 Things get a bit more complicated if between the (FIN -> ) and the (FIN <- ) there is more data in the <- direction. The idea remains the same: if you acknowledge a FIN, you increase the Ack number by one. ----------------------------------------------------------------------- It may be that both A and B are there. (Often). It may be that A is not there, but B is. (The example in the books) It may be that A is there but B is not. (Abbreviated four-way) It may be that neither is there. (Abreviated four-way) The first and second are ``four way handshakes''. The third and fourth are ``abbreviated four way handshakes''. ----------------------------------------------------------------------- Once more: FIN: -> Seq = x Ack = y (I have nothing more to say. Part of the four-way handshake.) Ordinary Ack <- Seq = y Ack = x (I acknowledge all data before the FIN -> , but not the FIN itself. NOT part of the four-way handshake.) Special Ack <- Seq = y Ack = x+1 (I acknowledge the FIN -> AND all data before it. Part of the four-way handshake.) FIN <- Seq = y Ack = x+1 (I have nothing more to say. Part of the four-way handshake.) Special Ack -> Seq = x+1 Ack = y+1 (I acknowledge receipt of your FIN. Part of the four-way handshake.) Please note: This complication is necessary because there might have been more data in the <- direction after the original FIN. We must distinguish between an acknowledgement that only acknowledges data, and an acknowledgement that acknowledges a FIN AND all preceding data. --- I expect you will understand this during the midterm and final. After the final all you need to remember is that there is some funny business with increasing ack sequence numbers during handshakes.