Friday, April 2, 2010


TCP builds sessions between devices using the TCP 3-Way Handshake. TCP uses sequence numbers and is reliable (requires acknowledgment). UDP on the other hand is connectionless. It uses best-effort delivery and is unreliable.
The sequence number in TCP allows reassembly of packets later on. This is especially important in the internet because your packets may take different paths and end up in mixed up order. TCP allows the receiver to reassemble the packets in the correct order.

The TCP 3-Way Handshake is like calling a phone. The first action is to call the target party. The called party then picks up. Finally, the caller says "Hello!". The first packet sent is called the SYN packet, which stands for Synchronize. The picking up of the phone is known as the SYN-ACK, which means Synchronization Acknowledgment. Finally, the caller then sends an ACK packet, which Acknowledges the establishment of the connection.

When packets are sent, they are sent with incremental sequence numbers. If sequence 10 is sent, there is an ACK for sequence 11. This is confusing because most people would expect an ACK for sequence 10. A good way to think of this is that ACK in terms of sequence numbers means that the computer is ready to receive the stated packet.

A TCP communication typically looks like:
Host A      --      Host B
SEQ10/ACK05 ->
            <- br="" seq05="">SEQ11/ACK06 ->
            <- pre="" seq06="">Of course, typical sequence numbers are much larger than what's typed here.

However, if actual communication is performed like what's depicted above, the communication would be very inefficient. To be efficient, a mechanism known as TCP windowing is used. TCP Windowing (or TCP Sliding Windows) is used to find the maximum transfer speed by doubling the amount of packets sent every transaction.
Host A                   Host B
[SEQ1]                   ->
                         <- br="">[SEQ3][SEQ2]             ->
                         <- br="">[SEQ7][SEQ6][SEQ5][SEQ4] ->
                         <- br="">[SEQ9][SEQ8][SEQ7]       ->
The sequence number actually reflects the number of bytes sent over. Therefore in real-life, expect much larger numbers. However, this concept still stands.

No comments :

Post a Comment