TCP Services
TCP Services
Transmission Control Protocol (TCP) is a connection-oriented and reliable transport-layer protocol. It provides several important services to applications running at the application layer.
The main TCP services discussed here are:
- Process-to-process communication
- Stream delivery service
- Sending and receiving buffers
- Segment-based transmission
- Full-duplex communication
- Multiplexing and demultiplexing
1. Process-to-Process Communication
Like UDP, TCP provides process-to-process communication.
The network layer provides host-to-host communication using IP addresses, while TCP identifies the particular application process using port numbers.
For example:
Source Host Destination Host 192.168.1.10 192.168.1.20 | | TCP port 50000 TCP port 80 | | Client process ─────────────────→ Web server
The combination of:
- IP address
- Port number
identifies a particular process.
TCP uses port numbers to establish communication between the appropriate processes.
2. Stream Delivery Service
This is one of the most important differences between TCP and UDP.
UDP
UDP is message-oriented.
Suppose an application gives UDP three messages:
Message 1 Message 2 Message 3
UDP treats each message as an independent user datagram.
Message 1 → UDP Datagram 1 Message 2 → UDP Datagram 2 Message 3 → UDP Datagram 3
The boundaries between the messages are preserved.
TCP
TCP is stream-oriented.
The sending application gives TCP a continuous stream of bytes.
Sending Process │ │ A B C D E F G H I J K ... ↓ TCP │ │ Stream of bytes ↓ Network │ ↓ TCP │ ↓ Receiving Process
TCP creates an imaginary "tube" between the two processes.
The sending process:
writes bytes into the stream
The receiving process:
reads bytes from the stream
The receiving application does not need to know how TCP divided the stream into segments.
Important point
TCP does not preserve application message boundaries.
For example, if an application writes:
HELLO WORLD
TCP sees a stream of bytes:
H E L L O W O R L D
It does not necessarily treat HELLO and WORLD as two separate messages.
3. Sending and Receiving Buffers
TCP uses buffers because the sending and receiving applications may operate at different speeds.
There are two buffers:
- Sending buffer
- Receiving buffer
These buffers are also important for TCP's flow control and error control.
Sending Buffer
The sending buffer contains three types of data:
1. Empty space
Space that can be filled by the sending application.
2. Sent but not acknowledged bytes
TCP keeps these bytes in the buffer until it receives an acknowledgment.
Sending Buffer ┌──────────┬─────────────────┬──────────────────┐ │ Empty │ Sent but not │ Written but │ │ │ acknowledged │ not yet sent │ └──────────┴─────────────────┴──────────────────┘
3. Written but not yet sent
These are bytes supplied by the application but waiting to be transmitted by TCP.
Receiving Buffer
The receiving buffer contains:
- Empty locations
- Received bytes waiting to be read by the application
Receiving Buffer ┌────────────────────┬──────────────────┐ │ Received but not │ Empty │ │ yet read │ │ └────────────────────┴──────────────────┘
When the receiving application reads bytes, those buffer locations become available again.
Why are buffers necessary?
Consider:
Application → TCP → Network → TCP → Application
The application and network may work at different speeds.
For example:
Application produces: 1000 bytes/sec TCP sends: 500 bytes/sec
The sending buffer temporarily stores the bytes that cannot yet be transmitted.
Similarly, if TCP receives data faster than the receiving application can consume it, the receiving buffer stores the received bytes.
4. Segment-Based Transmission
Although TCP provides a stream of bytes to applications, the network layer cannot directly transmit an unlimited stream.
Therefore, TCP divides the byte stream into smaller units called segments.
Application │ │ Stream of bytes ↓ TCP │ ├── Segment 1 ├── Segment 2 ├── Segment 3 └── Segment 4 ↓ Network Layer
TCP adds a TCP header to each segment.
The segment is then passed to the network layer.
The network layer encapsulates the TCP segment inside an IP datagram.
TCP Segment ┌─────────────────────┬─────────────────────┐ │ TCP Header │ Data │ └─────────────────────┴─────────────────────┘ ↓ IP Datagram ┌─────────────┬─────────────────────────────┐ │ IP Header │ TCP Segment │ └─────────────┴─────────────────────────────┘
Important point
TCP segments are not necessarily all the same size.
For example, one segment may carry 3 bytes while another may carry 5 bytes. In actual implementations, segments normally carry much larger amounts of data.
What happens if segments are lost or arrive out of order?
TCP handles these problems internally.
Segments may:
- arrive out of order,
- be lost,
- be corrupted,
- need retransmission.
TCP takes care of these problems using its reliability mechanisms.
The application process is normally unaware of these internal operations.
Thus, the application sees a reliable stream of bytes rather than individual unreliable segments.
5. Full-Duplex Communication
TCP provides full-duplex communication.
This means that data can flow in both directions simultaneously.
For example:
TCP Connection Client ─────────────────────→ Server ←─────────────────────
The client can send data to the server while the server is simultaneously sending data to the client.
Each TCP endpoint therefore has:
- A sending buffer
- A receiving buffer
Full Duplex Sending Buffer Client ─────────────────────→ Server ←───────────────────── Receiving Buffer
This makes TCP suitable for applications where both sides need to communicate simultaneously.
6. Multiplexing and Demultiplexing
TCP also performs multiplexing and demultiplexing, similar to UDP.
Multiplexing
At the sender, several application processes can use TCP.
Application 1 ──┐ Application 2 ──┼──→ TCP ──→ Network Application 3 ──┘
TCP collects data from different processes and sends it through the network.
Demultiplexing
At the receiving host, TCP identifies the appropriate process and delivers the data to it.
Network │ ↓ TCP │ ├──→ Application 1 ├──→ Application 2 └──→ Application 3
Important difference from UDP
Because TCP is connection-oriented, a separate TCP connection needs to be established for each pair of communicating processes.
7. TCP Is Connection-Oriented
The textbook emphasizes that TCP explicitly defines three phases:
1. Connection Establishment
The two TCP endpoints establish a logical connection.
Client ─── Connection Establishment ───→ Server
2. Data Transfer
After the connection is established, data is transferred as a reliable byte stream.
Client ═══════════════════════════════ Server Data Transfer
3. Connection Teardown
After communication is completed, the connection is terminated.
Client ─── Connection Teardown ───→ Server
This connection-oriented nature allows TCP to provide reliable communication.
TCP Services — Summary
| TCP Service | Explanation |
|---|---|
| Process-to-process communication | Uses IP addresses and port numbers to identify communicating processes |
| Stream delivery | Provides a continuous stream of bytes rather than individual messages |
| Sending buffer | Stores application data waiting to be sent and data awaiting acknowledgment |
| Receiving buffer | Stores received bytes until the application reads them |
| Segmentation | Divides the byte stream into TCP segments for transmission |
| Reliability | Handles lost, corrupted, and out-of-order segments transparently |
| Full-duplex communication | Allows data to flow in both directions simultaneously |
| Multiplexing | Allows multiple application processes to use TCP |
| Demultiplexing | Delivers received data to the appropriate application process |
| Connection-oriented service | Provides connection establishment, data transfer, and connection teardown |
TCP provides a reliable, connection-oriented, full-duplex, process-to-process byte-stream service, using buffers, segmentation, port numbers, and reliability mechanisms to hide network-level problems from the application.
Comments
Post a Comment