What is TCP protocol
What you will learn here about TCP protocol
- What is TCP protocol
- TCP packet format
- TCP connection establishment or TCP three way handshake
- TCP connection termination
What is TCP protocol
TCP stands for transmission control protocol. The TCP protocol is stream-oriented means it converts data received from the upper layer into segments (Segmentation). The TCP Protocol is the connection oriented means it establishes connection before start sending data. The TCP protocol uses Sequence number to deliver data reliably in a transmitted order.
TCP packet format
TCP protocol packet is 32 bit in length which is shown below. Source port and destination port number is 16 bit length.
The sequence and acknowledgment numbers are for numbering the data, at the byte level. This allows TCP to send 1024-byte blocks of data, incrementing the sequence number by 1024 between successive packets, or to send 1-byte telnet packets, incrementing the sequence number by 1 each time
- SYN: for SYNchronize; marks packets that are part of the new-connection handshake
- ACK: indicates that the header Acknowledgment ﬁeld is valid;
- FIN: for FINish; marks packets involved in the connection closing handshake
- PSH: for PuSH; marks “non-full” packets that should be delivered promptly at the far end
- RST: for ReSeT; indicates various error conditions
- URG: for URGent; part of a now-seldom-used mechanism for high-priority data
- CWR and ECE: part of the Explicit Congestion Notiﬁcation mechanism
TCP connection establishment
The TCP connection establishment or Three way handshake mechanism is shown below. Assume A is the Client (sender) and B is the Server (receiver). When the client wants to talk with the server, the client sends packets to the server with SYN=1 (SYN bit set) which indicates that the Client wants to talk with the server. When the server receives the packet with SYN=1, if the server is free, the server sends the packet with SYN=1 and ACK=1 which tells the client that the server is ready to talk. On the reception of a packet with SYN=1 and ACK=1, the client sends one more packet with ACK=1 which indicates the server that the client has received acknowledgment and now client is going to send the data.
TCP connection termination
The TCP connection termination mechanism is shown below. TCP connection termination is also called a four way handshake mechanism. Assume below A is client and B is the server. When the client wants to terminate the connection, it sends a packet with FIN=1. When Server receives the packet with FIN=1, the server understands the client wants to terminate the connection. In response to the received packet, the server sends a packet with ACK=1 which indicates that the server has received a connection termination request. The Sever also sends one more packet with FIN=1 which tells the client that the server has terminated connection from server side. Once the client receives FIN=1 from the server, the client sends a packet with ACK=1 which tells the server that the client has received ACK=1 and FIN=1 packet and connection terminated successfully.