What is Transmission Control Protocol (TCP ) ?
TCP (Transmission Control Protocol) is a set of rules (protocol) used along with the Internet Protocol (IP) to send data in the form of message units between computers over the Internet. While IP takes care of handling the actual delivery of the data, TCP takes care of keeping track of the individual units of data (called packets) that a message is divided into for efficient routing through the Internet.
TCP provides end-to-end reliability between the application process running on one computer system to another computer system by adding services on top of IP.
Basic Features of TCP :-
Some of the basic features of TCP are :-
- Data Transfer
- Flow Control
- Precedence and security
How it Works :-
There are four distinct elements that uniquely identify a TCP connections. They are :-
- IP address of the Sender
- IP address of the receiver
- TCP port of the sender
- TCP port of the receiver
To establish a TCP session, the two computers participating in the session must first go through what is known as the ” three-way handshake” . There are two scenarios where a three-way handshake would take place, namely :-
- Establishing a connection ( an active open )
- Terminating a connection ( an active close)
The steps in the connection establishment are as follows :-
- Client :- sends a message with the SYN flag on
- Server :- Replies to the client with a message that has SYN and ACK flag on.
- Client :- replies on the server’s SYN/ACK message with an ACK message.
TCP Header :-
The standard TCP Header is defined in RFC 791 and the TCP packet structure is illustrated as below picture :-
The TCP header is 20 bytes long, or up to 24 bytes with options. You need to understand each field in the TCP segment is :-
Source Port :- The port number of the application on the host sending the data.
Destination port :- The port number of the application requested on the destination host.
Sequence Number :- A number used by TCP that puts the data back in the correct order or re-transmits missing or damaged data, a process called sequencing.
Acknowledgment Number :- The TCP octet that is expected next.
Header length :- The number of 32-bit words in the TCP header. This indicates where the data begins. The TCP header (Even one including options ) is an integral number of 32-bits in length.
Reserved :- Always set to Zero
Code bits :- Control functions used to set up and terminate a session.
Window :- The window size the sender is willing to accept, in octets.
Checksum :-The cyclic redundancy check (CRC), because TCP doesn’t trust the lower layers and checks everything. The CRC checks the header and data fields.
Urgent :- A valid field only if the urgent pointer in the code bits is set. If so, this value indicates the offset from the current sequence number, in octates, where the first segment of non-urgent data begins.
Options :- May be 0 or a multiple of 32-bits, if any.
Data :- Handed down to the TCP protocol at the Transport layer, which includes the Upper layer headers.
You can easily view all the TCP header information with Wireshark.
Error Recovery :-
Also known as reliability, TCP provides error recovery during data transfer sessions between two end devices who have established a connection. The sequence and acknowledgment fields in the TCP header are used to track every byte of data transfer and ensure that missing bytes are retransmitted.
In below image , the Acknowledgment field sent by the web client (4000) implies the next byte to be received; this is called forward acknowledgment.
TCP Acknowledgment Without Errors :-
TCP Acknowledgment With Errors :-
Flow Control :-
Flow control is handled by TCP through a process called windowing. The two end devices negotiate the window size when initially establishing the connection; then they dynamically renegotiate window size during the life of the connection, increasing its size until it reaches the maximum window size of 65,535 bytes or until errors occur. Window size is specified in the window field of
the TCP header. After sending the amount of data specified in the window size, the source must receive an acknowledgment before sending the next window size of data.
Also Check :-
Hope you like my post.What is Transmission Control Protocol (TCP ). Please Share with others.