TCP (which means Transmission Control Protocol) is one of the main protocols of the transport layer of the TCP/IP model. It makes it possible, at application level, to manage data coming from (or going to) the lower layer of the model (i.e. the IP protocol). When data is provided to the IP protocol, it encapsulates them in IP datagrams, by fixing the protocol field to 6 (so that it knows in advance that the protocol is TCP...). TCP is a connection orientated protocol, i.e. it enables two machines which are communicating to control the status of the transmission.
The main characteristics of the TCP protocol are as follows:
Using the TCP protocol, applications can communicate securely (thanks to the TCP protocol's acknowledgements system), independently from the lower layers. This means that routers (which work in the internet layer) only have to route data in the form of datagrams, without being concerned with data monitoring because this is performed by the transport layer (or more specifically by the TCP protocol).
During a communication using the TCP protocol, the two machines must establish a connection. The originator machine (the one which requests the connection) is called the client, while the recipient machine is called the server. So it is said that we are in a Client-Server environment.
The machines in such an environment communicate in online mode, i.e. the communication takes place in both directions.
To enable the communication and all the controls which accompany it to operate well, the data is encapsulated, i.e. a header is added to data packets which will enable the transmissions to be synchronized and ensure their reception.
TCP makes it possible to carry out an important task: multiplexing/demultiplexing, i.e. to convey data from various applications on the same line or in other words put information arriving in parallel into order.
These operations are conducted using the concept of ports (or sockets), i.e. a number linked to an application type which, when combined with an IP address, makes it possible to uniquely determine an application which is running on a given machine.
A TCP segment is made up as follows:
|Source port||Destination port|
Meanings of the different fields:
The TCP protocol makes it possible to ensure reliable data transfer, although it uses the IP protocol, which does not include any monitoring of datagram delivery.
In reality, the TCP protocol has an acknowledgement system
enabling the client and server to ensure mutual receipt of data.
When a segment is issued, a sequence number is linked to it. Upon receipt of a data segment, the recipient machine will return a data segment where the ACK flag is set to 1 (in order to signal that it is an acknowledgement) accompanied by an acknowledgement number equal to the previous sequence number.
In addition, using a timer which starts upon receipt of a segment at the level of the originator machine, the segment is resent when the time allowed has passed, because in this case the originator machine considers that the segment is lost...
However, if the segment is not lost and it arrives at the destination, the recipient machine will know, thanks to the sequence number that it is a duplication and will only retain the last segment arrived at the destination...
Considering that this communication process, which takes place using data transmission and acknowledgement, is based on a sequence number, the originator and recipient machines (client and server) must know the initial sequence number of the other machine.
Establishing the connection between two applications is often done according to the following schema:
The two machines must then synchronize their sequences using a mechanism commonly called a three ways handshake that is also found during the closure of the session.
This dialogue makes it possible to start the communication, it takes place in three stages, as its name indicates:
Following this sequence involving three exchanges the two machines are synchronized and communication can begin!
In many cases, it is possible to limit the number of acknowledgements, in order to relieve traffic on the network, by fixing a sequence number at the end of which an acknowledgement is required. This number is in fact stored in the window field of the TCP/IP header.
This method is effectively called the "sliding window method" because to some extent a range of sequences is defined that does not need acknowledgements and which moves as acknowledgements are received.
In addition, the size of this window is not fixed. In fact, the server can include the size of the window which seems most suitable in its acknowledgements by storing it in the window field. So, when the acknowledgement indicates a request to increase the window, the client will move the right border of the window.
Conversely, in the case of a reduction, the client will not move the right border of the window towards the left but wait for the left border to advance (with the arrival of the acknowledgements).
The client can request to end a connection in the same way as the server.
Ending a connection is done in the following way:
For more information on TCP protocol, please refer to RFC793 which explains the protocol in detail: