A bit about TCP

In this post I am going to talk about one of the celebrities of the protocol world; Transmission Control Protocol or as it is known to its friends, TCP. TCP is one of the internet’s big hitters, along with its layer 3 cousin IP, it lends its name to the TCP/IP protocol suite, which is a collection of standardised protocols commonly used on the internet. TCP lives in the transport layer (layer 4) of the OSI model and as such is a transportation protocol.

TCP provides reliability to the data that is being sent over the network, a lot of the core internet technologies make use of TCP to ensure that all the data they send is received intact and free of errors, TCP does this independently and hidden from the higher layer application that is making use of it, be it POP3 or IMAP that use TCP in email communications, or FTP that uses TCP in file transfers. For example if you are browsing the web and wish to view a web page, your browser will make a HTTP (a layer 7 application protocol for requesting resources most commonly HTML files) request to the websites host server, if just a single bit is missing from the requested HTML file then it will be corrupt rendering it unintelligible by the web browser. TCP provides reliability and error checking to ensure that every bit of the requested file is received intact by the requesting browser; this will be done completely transparently to the browser, for all it knows TCP does not even exist.

TCP Header

TCP is a connection oriented protocol, what this means is that a connection between both devices in the conversation need to have a connection established to allow them to reliably send data between each other, think of it as a phone call, if you call someone you won’t start speaking until the person at the other end has answered and acknowledged and confirmed that you have a connection by saying “Hello”.

When data is received from the higher layer protocols, TCP splits the data into chunks, and gives each chunk of data a TCP header, this header will include a sequence number assigned to each chunk so that all data can be reassembled in the correct order on the receiving side of the transmission, the chunks are now known as TCP segments. The sequence number not only allows for data to be reconstructed correctly they also assist with reliability, but before we get to that, first we have to establish a reliable connection between two devices.

Three-way Handshake

This connection is established by using what is known as the Three-way Hand Shake, the device initiating the connection will transmit a SYN segment, this synchronises the sequence numbers and specifies what the Initial Sequence Number (ISN) will be, the ISN will be incremented by one for each transmitted segment. The receiver will then reply with a SYN-ACK segment, this acknowledges the request to establish a connection from the initiating device. The third segment that completes the Three-way Handshake process is sent from the initiator is an ACK or acknowledgment message.

Using a cumulative acknowledgment scheme, the receiver knows what sequence number it expects to receive next, if does not receive the number it expects it will ask for it to be retransmitted, additionally if a segment is retransmitted and received twice the sequence numbers allow for that packet to be discarded.
The TCP header also contains a number of other fields, one dedicated to error detection; this is the checksum field, a small hash sum that checks and detects errors in the segment. Source and destination port numbers, each application use ports to communicate, for example the HTTP protocol uses port 80 to receive segments.

TCP also has mechanisms to control the flow of segments, this prevents a receiving device that cannot process the TCP segments as fast as its corresponding device from being overwhelmed, it does this by implementing the sliding window system, in which the receiving device tells the sender how much information it can buffer, the sending device will then only send the amount of data that the receiver can process in a timely fashion, allowing for the conversation to proceed smoothly.

It is thanks to some of the features outlined above that makes TCP the most used reliable transport protocol on the internet, but this post is not a complete list of the features and benefits of TCP, several other features are built in to the protocol, including congestion control, to avoid a drop in network performance, maximum segment size, that specifies the size of each segment that is sent and a number of other features that can be read about in detail in the Internet Engineering Task Force‘s (IETF) RFC standards that specify the exact operation of TCP.

Leave a Reply