Main menu


WHAT IS Protocols TCP? EVERYTHING You Need To Know About Protocol TCP

Transport Control Protocol (TCP) is an important network protocol used to send data over networks. In the networking world, a protocol is a set of rules and procedures that control how data transmission is carried out, with anyone around the world doing the same, regardless of location, software, or hardware used.

WHAT IS Protocols TCP? EVERYTHING You Need To Know About Protocol TCP

TCP Definition:

It is called the Transmission Control Protocol, or simply called “TCP”, which is the protocol used to manage communications, transfer and flow data effectively, and the “TCP” protocol is a protocol approved by the “Internet Society” ”, which is the body responsible for defining the foundations of online communication.

TCP is a protocol that supports communication processes in which the path between source and destination must be determined (established) before beginning to send data, which makes it reliable in terms of end-to-end communication.

According to the RFC-793 document, the TCP protocol works between the upper-level layers and the Internet protocol layer, according to the OSI standard model, specifically in the Transportation Layer (the fourth layer).

The TCP protocol is responsible for the flow of data between two devices, and there is always the device that sends data and is called the source or sender, and the other device that receives data is called the destination or receiver, and TCP may be used to transfer data between two programs on one device, but for simplicity, we will assume Transfer data between two devices connected to a single network.

How does TCP handle data?

When the source device selects the data to be sent to the receiving device, the TCP protocol splits this data into several parts (or segments), each of these segments consists of a sequence of smaller units, and the size of each unit is one byte.

As we learned in binary data representation, each byte consists of 8 bits, and the bit is the smallest unit, which contains 0 or 1.

According to the OSI standard communication model, each layer or level of the seven levels adds a set of data called a header to each segment of the header that is dealt, the TCP protocol also adds a set of data, for each segment or byte wants to send.

Read more about Address IP here.

Format for the introduction of the TCP data segment:

As we mentioned that the “TCP” protocol deals with the Internet Protocol - IP layer in the receiving device, so the source sends “TCP” segments as data units of IP format, so that the receiver can deal with this data, in addition to the introduction of the “TCP” segment, which Called (Header), the introduction of the TCP data segment consists of the following:

Protocol TCP

The previous table consists of a set of rows (Rows) so that each row consists of 32 bits, and each row is divided into four sections, each section consists of 8 bits or bytes, and each byte starts from the left in the order of its constituent bits from 7 to zero, which is The so-called Little Indian, which is outside the scope of this article, is detailed as follows:

“Source port” field:

It is a 16-bit field in Unsigned Binary Number format, which means that the number inside it can be between 0, 216-1, that is, it consists of a number from zero to 65,535, which represents the number of the source communication port, or in short it is The port number of the device sending the data.

Destination port field:

It is also a 16-bit field and represents the number of the destination communication port (the data receiving device).

Flags field:

Looking at the previous table, you will find six fields colored green, each of them contains 1 bit so that its value is either 0 or 1, and each field of them has a name written inside it, and it has meaning if its value is equal to one, and we will deal with them in detail, but if You indicate Flag XXX or control bit XXX, it means the value of the bit in field XXX.

“Sequence Number” field:

It is a 32-bit field, and the value inside it depends on the value of the Flag (SYN):

  • If the value of Flag (SYN) is 1: then the value of the field is the initial sequence number of the segment being transmitted called initial sequence number (ISN), in which case the sequence number of the first byte will become ISN+1.
  • If the value of Flag (SYN) is 0: this means that the value of the field is the serial number of the byte being sent.

“Acknowledgment Number” field:

It is a 32-bit field, and its value depends on the Flag (ACK). If the value of the ACK control bit is 1, this means that the value of this field contains the next serial number expected to be received, and the control bit is always set after the connection is established.

Data Offset field:

It is a 4-bit field, meaning that its value can be from 0 to 15, but it has a minimum and a maximum of 5 to 15, meaning that the lowest value that this field can contain is 0101, which is the value of the number 5 in the binary system, and this field expresses About the number of words (Words) at the front of the TCP section, and the word here means that every 32 bits are called a word, or in a simplified way if you look at the previous table you will find that it contains five rows, before the last row, and after the end of the table the data we want is merged Send it, and you will notice that the last row in the table called Options, does not have a specific value like the rest of the rows, it may contain any number of bits, and therefore the number of rows is determined so that the receiving device can identify and separate the data from the TCP foreground.

“Reserved” field:

It is a 6-bit field, their value is always zero, but in some updates to the TCP standard, some control bits (Flags) were added, but they are still being tested, so I have not added them to this model.

Field “Flags/Control Bits”:

It is a 6-bit field, in the table, they are represented in green, and each bit of them expresses a special case at the front of the data segment, and their details are as follows.

  • Urgent - URG Used to read the data of the Urgent Pointer field.
  • Acknowledgment - ACK As we learned about its use with the Acknowledgment field.
  • push – PSH Used to execute the PUSH command.
  • Reset – RST is used to reset the connection via the RESET command.
  • Synchronize - SYN Used to find the value of the Sequence Number field, as we already knew about it.
  • FINISHED - FIN means that there is no more data coming from the sender, so the connection is terminated.

“Window Size” field:

It is a 16-bit field, whose value contains the number of bytes in the sequence that is currently being transmitted.

Checksum field:

It is a 16-bit field, and it is used to detect errors or not during data transfer, as it uses some calculations using “Source Address” and “Destination Address” in addition to the length of the TCP introduction in order to detect errors that may occur during a transfer process. data.

Urgent Pointer field:

A 16-bit field whose value contains the address of the urgent byte in the sequence (a segment of data), and the content of this field is only considered if the value of the Flag (URG) is 1, in short, sometimes a portion of the data is specified Which is sent as urgent data, i.e. it must be sent before any other data, in this case, the “URG” bit is used, together with the “Urgent Pointer” to specify the urgent data.

"Options" field:

This field may contain data between 0 and 320 bits, any number that is divisible by 32, as we indicated in the Data Offset field, it is considered the last field to be added by the TCP protocol, and it is an optional field, meaning that it can not be specified Any additional data, and just one byte consisting of zeros as a separator between the data being sent and the header that we have covered so far.

How does TCP work?

TCP on one side (the source) deals with the processes of the users or application layer, and on the other side (the destination) deals with a lower level protocol such as Internet Protocol (IP).

The TCP work steps can be divided into three basic stages, starting with the source device sending a message to the destination device that it wants to send some data to it, then waiting for the source until it is answered with approval from the destination, and the sending of data is not started until the response is done With approval, and here the process of sending data begins, and this is the second stage, and with the end of sending all the data, the third stage begins, which is concerned with ending the connection and giving up the resources previously reserved to complete the data transfer process.

The TCP is usually managed by the operating system, where each operating system provides an interface to deal with this protocol, and this interface is usually called the “Internet Socket API” that allows programmers to create programs with the aim of dealing with TCP.