Kahibaro
Discord Login Register

4.3.2 TCP Overview

Introduction

The Transmission Control Protocol, or TCP, is one of the core protocols used on the internet. It belongs to the transport layer of networking models and is responsible for getting data from one application to another reliably and in the correct order. Where lower layers focus on sending individual bits and packets across links and between devices, TCP focuses on managing a conversation between two endpoints.

In this chapter you will see what makes TCP special as a transport protocol, what kind of service it provides to applications, and how it behaves at a high level. Detailed mechanisms such as the three way handshake, reliable transmission, flow control, and congestion control are covered in their own chapters, so here we focus on the big picture.

TCP as a Connection Oriented Protocol

One of the most important characteristics of TCP is that it is connection oriented. Before real application data flows, TCP creates a logical connection between two endpoints, typically identified by IP addresses and port numbers. This connection is not a physical circuit. Instead, it is an agreement between the two hosts to track and manage a specific data flow.

Being connection oriented means that TCP keeps internal state for each connection. This state includes information such as sequence numbers, window sizes, and the current phase of the connection. During the lifetime of a connection, TCP uses this state to ensure that data travels reliably and in order, even if the underlying network occasionally drops, duplicates, or reorders packets.

Because of the connection oriented nature, applications that use TCP usually follow this pattern. One side acts as a server and listens on a specific TCP port. The other side acts as a client and actively initiates a connection to that listening port. Once established, the connection acts like a bidirectional pipe between the two application processes.

TCP vs the Underlying Network

The internet protocol that works underneath TCP, IPv4 or IPv6, offers a best effort service. IP packets might be lost, arrive late, arrive in a different order than they were sent, or even be duplicated. IP does not try to fix these problems. It simply forwards packets from source to destination as efficiently as it can.

TCP sits above IP and hides many of these imperfections from applications. From the point of view of a programmer who uses TCP, the network often appears as if it were a reliable stream. The application writes bytes into a TCP socket and reads bytes from it. TCP is responsible for turning this stream of bytes into individual segments suitable for transmission, sending them using IP, and dealing with any problems that arise during transit.

It is important to understand that the application sees a stream of bytes, not packets. Packet boundaries are a concern of TCP and IP, not of the application using TCP. This is very different from protocols that are message oriented, where each send corresponds to a specific message unit.

TCP as a Byte Stream Service

TCP provides a byte stream service. In practice this means that TCP treats the data from an application as a continuous sequence of bytes, without any concept of separate messages or records. The application might send some bytes with one write call and more bytes with another, but the receiver will simply see a continuous sequence. It might read more or fewer bytes at a time than what the sender originally wrote.

Internally, TCP divides this byte stream into chunks called segments. These segments are sized to fit within limits such as the maximum segment size and the maximum transmission unit of the path. The sender can choose how to group bytes into segments, and this grouping is not visible to the receiving application.

Because of this, the application is responsible for defining any boundaries that matter at the application layer. For example, an application protocol might define that a line ending marks the end of a command, or that the first few bytes of a message specify its length. TCP does not help with this and simply ensures that all bytes are delivered, in sequence, if possible.

Core TCP Features at a High Level

TCP offers several important features that together create a reliable and orderly service. These features are explored in depth in later chapters, but it is useful to know their roles in an overview.

First, TCP ensures ordered delivery. Each byte in the stream has a position in a sequence. On the wire, segments carry sequence numbers that identify the position of the first byte in the segment. If packets arrive out of order, TCP uses these numbers to reassemble the data in the correct sequence before presenting it to the application.

Second, TCP provides reliability. If a segment is lost, TCP detects the loss and retransmits the missing data. It does this using acknowledgments and timers. The receiver informs the sender about which data has been successfully received, and the sender uses timeouts or patterns in acknowledgments to infer that some data was not delivered.

Third, TCP handles flow control. This protects the receiver from being overwhelmed by more data than it can handle. The receiver advertises a window that tells the sender how much more data it can accept at a given time. The sender respects this limit and adjusts its sending rate accordingly.

Fourth, TCP performs congestion control. This protects the network as a whole from overload. By observing packet loss and timing, TCP adapts its sending behavior to be more careful when the network seems congested and more aggressive when the path appears to have available capacity.

Finally, TCP supports full duplex communication. Once a connection is established, both sides can send and receive data independently and simultaneously. The byte stream is conceptually two directional, one stream in each direction, each with its own sequence and control.

Typical Uses of TCP

Many of the most familiar internet applications use TCP because they require reliable delivery and an ordered stream of data. Web browsing with HTTP and HTTPS, email protocols like SMTP, POP3, and IMAP, file transfer with FTP or SFTP, and remote login via SSH are all common examples of TCP based applications.

These applications benefit from TCP because they deal with structured data where errors, missing parts, or incorrect ordering can break the user experience or corrupt information. For instance, an incomplete file transfer is not acceptable, and a partial or wrongly ordered web page can cause failures in how a browser displays content or runs scripts.

Some applications that prioritize speed or can tolerate loss, such as real time voice or video, often choose a different transport protocol that does not provide the same guarantees. The comparison between TCP and such alternatives belongs to later chapters, but it is useful here to recognize that TCP is not the only option for transport, it is just the most common one for reliable services.

TCP Segments and Basic Header Ideas

TCP uses segments as its transport layer units. Each segment contains a TCP header followed by a portion of the byte stream as payload. The header carries information such as source and destination ports, sequence and acknowledgment numbers, flags that indicate control information, and other fields needed to manage the connection.

Although the detailed structure of the header is covered elsewhere, at this overview level it is enough to know that sequence numbers and acknowledgments form the backbone of TCP’s reliability and ordering. Control flags indicate events such as connection setup, connection termination, or urgent conditions. Window size fields support flow control, and optional fields allow features like scaling of window sizes or selective acknowledgment.

The size of a TCP segment cannot exceed certain limits on the path, so TCP interacts with the underlying IP layer to respect the maximum transmission unit. The segment size also affects performance, because larger segments can reduce per packet overhead, while smaller segments may be preferable for some interactive applications.

Connection Lifecycle in Broad Terms

A TCP connection goes through a lifecycle. In the beginning, the client and server have no shared state. Then they perform a process to set up a connection. After setup, data can flow back and forth as needed. When the communication is done, the connection is closed in a controlled way.

In the setup phase, both sides agree on initial sequence numbers and some capabilities. During the data transfer phase, they exchange segments that carry both data and control information, and they acknowledge each other’s data. During closing, they inform each other that no more data will be sent, and they eventually free the resources associated with the connection.

At each phase, TCP uses well defined states. These states help the protocol to handle packets that arrive late or out of order with respect to previous events, and to behave correctly in unusual situations such as one side crashing and later coming back. A complete state diagram is more detailed and is introduced in later discussions, but the idea of distinct phases is important to the overview.

Port Numbers and Multiplexing

Although port numbers and sockets are covered separately, it is useful in a TCP overview to see how they relate to TCP connections. A TCP connection is identified by four key values. These are the source IP address, source TCP port, destination IP address, and destination TCP port. This is sometimes called a 4 tuple.

Because of this 4 tuple, many connections can exist at the same time on a single host, even if they involve the same application. For example, a web server might listen on TCP port 80, but many clients can connect to it at the same time from different source ports and IP addresses. The server’s TCP stack keeps track of each connection separately, using the full 4 tuple to distinguish them.

This ability to multiplex many logical connections over a single network interface and IP address is one of TCP’s strengths. It allows modern servers to support thousands or even millions of concurrent sessions, depending on hardware and configuration.

Reliability and Performance Tradeoffs

TCP aims to provide reliability, but this comes with tradeoffs. Retransmissions, acknowledgments, and timers all add overhead. They increase the amount of control traffic and introduce delays when losses or reordering occur. For applications that value integrity and ordered delivery above all else, such as file transfer or web browsing, this overhead is acceptable.

However, some applications favor timeliness over perfection. A small glitch in a live audio stream might be preferable to waiting for a retransmitted packet. In such cases, the strict reliability and ordering of TCP can actually harm the user experience, because late data might be useless. That is one reason why other transport protocols exist and are better suited to certain real time tasks.

TCP also has built in mechanisms to adapt its sending behavior, which can sometimes interact in complex ways with application patterns and changing network conditions. Tuning these behaviors and understanding them in detail is part of more advanced study, but at an overview level it is important to remember that TCP is not a simple fire and forget tool. It is an active participant in the way traffic flows through the network.

Key Properties at a Glance

The essential characteristics of TCP can be summarized in a compact form. The following table shows some of the most important properties that define TCP’s role.

PropertyTCP Behavior
Connection styleConnection oriented, with setup and teardown
Data abstractionReliable, ordered byte stream
Communication directionFull duplex, simultaneous send and receive
Delivery guaranteesRetransmission of lost data, in order delivery
Flow protectionReceiver driven flow control
Network protectionSending rate adjusted by congestion control
Unit on the wireSegment, with TCP header and data payload

These properties together explain why TCP is used so widely for general purpose and business critical network applications. It provides a trustworthy foundation upon which many higher level protocols are built.

Key statement: TCP provides a reliable, ordered, connection oriented byte stream service between applications, built on top of an unreliable, best effort IP network.

Conclusion

TCP is the workhorse transport protocol of the internet. It takes the unpredictable behavior of the underlying network and, as far as possible, turns it into a dependable communication channel for applications. By maintaining connection state, numbering bytes, acknowledging received data, controlling flow, and adapting to congestion, TCP offers a robust service that suits a wide range of uses.

In the following chapters, you will examine the internal mechanisms that make this possible. You will see how connections are created with a three way handshake, how reliability is achieved, how TCP keeps senders from overwhelming receivers or the network, and how TCP compares with alternative transport protocols.

Views: 43

Comments

Please login to add a comment.

Don't have an account? Register now!