NETWORK ~ TCP protocol
TCP works with the Internet Protocol (IP), which defines how computers send data packets to each other. Both TCP and IP are the basic rules that define the Internet. The TCP protocol is defined by the IETF (Internet Engineering Task Force) in the document RFC (Request for Comment) 793. In this article, we will see how TCP works.
TCP is a connection-oriented protocol, which means that a connection is established and maintained until the programs at each end have finished exchanging messages. It determines how to divide application layer data into packets that can be carried by networks, so it sends packets to the network layer, handles flow control and is designed to ensure error-free data transmission, handles retransmission of lost or truncated packets, and acknowledges all incoming packets.
In the OSI (Open Systems Interconnection) communication model, TCP covers parts of Layer 4 (transport layer), and parts of Layer 5 (session layer).
For example, when a Web server sends an HTML file to a client, it uses the HTTP protocol to do so. The HTTP protocol at the application layer asks the TCP protocol at the transport layer to set up the connection and send the file. The TCP stack divides the file into packets, numbers them, and then passes them individually to the IP layer for delivery. Although each packet has the same source and destination IP addresses, packets can be sent over multiple routes. The client computer's transport layer waits for all the packets to arrive, then recognizes the ones it receives and requests retransmission if it doesn't (based on missing packet numbers), then assembles them into a file and sends the file to the recipient application layer.
TCP header format:
Source port (16 bits): It identifies the port of the sending application.
Destination port (16 bits): It identifies the port of the receiving application.
Sequence number (32 bits):
- TCP assigns a unique sequence number to each byte of data contained in the TCP segment.
- This field contains the sequence number of the first data byte.
Acknowledgement number (32 bits):
- It contains the sequence number of the byte that the receiver expects to receive next from the sender.
- It is always the sequence number of the last received byte + 1.
Header Length (Hlen - 4 bits): It contains the length of the TCP header.
Reserved bits (6 bits): These bits are not used.
URG bit: The URG bit is used to process certain data urgently.
ACK Bit: The ACK bit indicates whether the acknowledgement number field is valid or not.
PSH bit: The PSH bit is used to send the entire buffer immediately to the receiving application.
RST bit: The RST bit is used to reset the TCP connection.
SYN bit: The SYN bit is used to synchronize the sequence numbers.
FIN bit: The FIN bit is used to terminate the TCP connection.
Window size(16 bits): It indicates the amount of data (in bytes) that the sender can receive without acknowledgment, and it is used for flow control.
Checksum(16 bits): This field is used for error checking. It checks the integrity of the data in the TCP load. The sender adds the CRC checksum to the Checksum field before sending the data.
Urgent Pointer (16 bits):
It indicates how much data in the current segment counting for the first data byte is urgent. This field is considered valid and evaluated only if the URG bit is set to 1.
Options:
The options field is used for several purposes. The size of the field varies from 0 to 40 bytes.
Comments
Post a Comment