The TCP/IP model helps to determine how one computing device would connect to the internet and how data transmission happens between them. It helps to create a virtual network while several computing devices are connected to each other. TCP/IP stands for Transmission control protocol and Internet protocol and it is specifically designed to offer highly reliable , end to end byte stream over an unreliable internetwork.
Today we look more in detail about how TCP/IP offers reliable transmission using 3-way handshake, how TCP 3-way handshake works, its features etc.
What is TCP 3-Way Handshake?
TCP/IP protocol operates at the network layer in OSI stack. TCP/IP model which is derived before OSI model dictates how TCP/IP communication works.
TCP/IP has several characteristics as under:
- It supports flexible TCP/IP architecture
- It is easy to add more systems to network
- The network remains intact until source and destination machines are working in proper manner
- TCP is a connection-oriented protocol
- It offers reliability and ensure that data which arrives out of sequence should be put back to order
- TCP allows to implement flow control to ensure sender never overloads receiver with data
TCP/IP provides reliable communication with Positive Acknowledgement and Retransmission (PAR). The Protocol data unit (PDU) of transport layer also known as segment. A device using PAR resends the data until it is acknowledged. If a data unit is found damaged at the receiver end, then the segment is discarded. Sender has to resend the data unit for positive acknowledgement
How does TCP 3-way handshake (SYN, SYN + ACK, ACK) work?
Since TCP is a connection-oriented protocol a connection is mandate to be established before two devices start communication. TCP uses a process of three-way handshake to negotiate the sequence and acknowledgement fields to initiate a session. The graphical representation of process is as under:
- The three-way handshake starts with Host A initiates connection by sending the TCP SYN packet to the destination host. The packet contains a random sequence number (e.g., 1234) which indicates the beginning of the sequence number of data that host A will be transmitting.
- The server receives the packet and responds with his own sequence number. This response also includes the acknowledgement number which is increment of host A sequence number by ‘1’
- Host A acknowledges the server response by sending acknowledgement number which is server sequence number incremented by ‘1’. Once they establish a reliable connection, actual data transfer start.
Once the data transmission process is completed. TCP will terminate the connection between two devices. This is a four-step process as outlined below.
- The client application who wants to close connection send a TCP segment with the FIN flag set as ‘1’
- The server receives the TCP segment and acknowledge it will ACK
- Server sends its own TCP segment with FIN flag set to ‘1’ to client to terminate connection
- The client acknowledges the server FIN segment and connection is closed.