This is (Fourth Article) in continuation of our last one article, a new series of networking articles. In this segment, we are going to discuss the idea of TCP Layer and how the TCP packets are developed.
The Transmission Control Protocol (TCP) layer correlates with layer 4 of Open Systems Interconnection, created by the International Standards Organization (known as OSI/ISO protocol). This is the transport protocol. The layer works in connection-oriented mode and ensures the delivery of information. TCP gives the assistance of breaking messages into datagrams at the source end, retransmitting any datagram that has been lost or acknowledged negatively, sequencing the datagrams, etc.
Assistance in the layer is ensured by the acknowledgment of receipt of information from the receiving side. If the acknowledgment is negative, information is retransmitted and if it is not received inside a timeframe, known as time-out period, retransmission of the datagram is done.
The TCP layer makes TCP packets using the information received from other layers. A TCP packet has numerous header fields, as appeared in the diagram.
Like IP, a TCP header is least 20 bytes long. It has the following fields:
A 16-Bit Source Port Number, which makes reference to a virtual circuit between two end communicating stations. The port is called a socket or session. In a port or socket, more than one process can interact over a session between end communicating stations.
A 16-Bit Destination Port, which makes reference to the port of the receiving end of a process. TCP ports are defined in a standard way. A few examples of these ports are 9 for transmission discard, 20 for file transfer protocol (FTP) data, 25 for SMTP email applications, 80 for hypertext transfer protocol (HTTP) and so on.
A 32-Bit Sequence Number, which is used to allow a sequence number to every TCP pack. The transmitter allocates the sequence number. The receiver reads the grouping number of packs, guarantees that all packs are received. Using a sequence number method, packets received out of order are arranged in their correct order, the receiver also distinguishes duplicates of the packets, assuming any and take corrective measures appropriately.
A 32-Bit Acknowledgement Field, which is used to send an acknowledgment of the packet received accurately. The receiver plays out this function. It checks the sequence number of a received packet. If the packet is received without error, the receiver sends an acknowledgment number using the sequence number of the packet to inform the sender that the packet has been received accurately.
A 4-Bit Offset Field, which is used to show the number of header fields. The offset field is also called header length or HELEN. Using this field, the receiver decides the beginning of the data field so information can be derived from the received packet.
Flags, Window, and Urgent Pointers are used to the interface and deal with the TCP connection. SYN (Synchronization), ACK (Acknowledgement) and FIN (Finish) flags are one-bit each. These are used to set up a TCP connection. TCP is a reliable and connection-oriented protocol. A TCP session needs a virtual connection, which is set up by a procedure called TCP handshake.
TCP Handshake – To set up a connection, the sender sends a TCP packet with SYN flag set to 1 and ACK flag set to 0. When the receiver gets this packet accurately, it reacts by sending a packet to the sender with both SYN and ACK flags set as 1 (SYN=1 and ACK=1). When the sender gets the right packet from the receiver, then it sends another packet with an ACK flag set to 1 (that is, ACK=1). The connection is then settled.
After the connection is built up, communicating parties can perform transmission in full-duplex mode (speak with each other in both directions). The connection can be ended by any station, either sender or receiver, by sending a packet with the FIN flag set i.e. FIN=1. For instance, after transmitting all information, the sender can send a packet with the FIN flag set to 1. At the point when this packet is recognized by the receiver, the connection is ended.
A 16-Bit Window Flag, which demonstrates the number of bytes that the sender can transmit without getting acknowledgments from the receiver. This field is used by the receiver to notify the sender about the availability regarding the buffer size in the receiver. In light of this information, the sender controls the flow of packets. The flow of packets is controlled by the window field.
The Urgent Pointer Field, which is used to alert the receiver about approaching urgent information and demonstrates the end of the urgent information within the sequence of the transmission of packets, URG (Urgent) flag is set (that is, URG=1).
Reserved Bits (six bits) are for the future. All flags URG, ACK, SYN, FIN, RST, and PSH – together are known as Control Fields of TCP. PSH flag is set when the receiver is noticed to pass the information immediately to the application. RST flag is used to end the TCP connections. At the point when this flag is set, the receiver is advised to end the connection for an irregular condition.
The Option Header can be of a maximum of 40 bytes and is constantly a multiple of four bytes. To make it a multiple of four bytes Padding might be used, whenever required. A couple of significant Options of TCP packet are given below:
Maximum Segment Size (MSS) Option: This is used to demonstrate the greatest size of the portion that the sender can acknowledge. This option is used during the connection establishment stage. The sender specifies the MSS.
Window Scale Choice (WSO): The maximum admissible window size is 65,535 bytes. The TCP window scale option is an option to expand the receive window size permitted in the Transmission Control Protocol over its previous maximum value of 65,535 bytes.
Times Stamp Option: This is used for figuring the time-out period helpful for flow control.
TCP divides information into reasonable packets that are easier to manage. It gives an ensured error-free connection. TCP breaks a network system service packet into a few packets. If an error occurs, a small packet can be retransmitted rather than 1 the entire packet.
TCP uses a header to build up a virtual connection with the successful transmission of packets and the completion of transmission of the entire message. Source and destination port fields keep the trace of packets. Packets having a place with different applications, for example, messages, online diagrams, and various running programs can run simultaneously dependent on the trace of packets. The sequence number is used to reassemble the packets at the receiver.
The receiver, on accepting a packet, performs checksum operation to detect errors. If the packet is received error-free, a positive affirmation is sent. If the packet is received incorrectly, a negative affirmation is sent.