The Transmission Control Protocol (TCP) is one of the core protocols of the [Internet Protocol](Internet%20Protocol.md) (IP) suite. It operates at the transport layer and provides reliable, connection-oriented communication between devices on a network. TCP ensures the ordered and error-checked delivery of data, making it suitable for applications where accuracy and reliability are paramount.
- TCP establishes a connection between two devices before data exchange. This connection is maintained throughout the communication session.
### 2. **Reliability:**
- TCP ensures the reliable delivery of data by using acknowledgments and retransmissions. If a segment is not acknowledged, it is retransmitted to ensure data integrity.
### 3. **Ordered Data Delivery:**
- Data sent over a TCP connection is delivered in the same order in which it was sent. This is achieved through sequence numbers assigned to each segment.
### 4. **Flow Control:**
- TCP incorporates flow control mechanisms to prevent a fast sender from overwhelming a slow receiver. It uses a sliding window mechanism to manage the flow of data.
### 5. **Full-Duplex Communication:**
- TCP supports full-duplex communication, allowing data to be sent and received simultaneously by both communicating devices.
## TCP Operation
### 1. **Three-Way Handshake:**
- TCP begins with a three-way handshake to establish a connection. This involves SYN (synchronize), SYN-ACK (synchronize acknowledgment), and ACK (acknowledge) segments.
### 2. **Data Transfer:**
- Once the connection is established, data can be transferred between the devices. Each segment is acknowledged, and retransmissions occur in case of lost or corrupted data.
### 3. **Connection Termination:**
- TCP ensures a reliable connection termination through a four-way handshake involving FIN (finish) and ACK segments.
## TCP Header
The TCP header includes various fields, including:
- **Source and Destination Port Numbers:** Identify the source and destination applications on the devices.
- **Sequence Number and Acknowledgment Number:** Manage the ordering and acknowledgment of data segments.
- **Window Size:** Specifies the size of the sender's receive window for flow control.
- **Checksum:** Ensures the integrity of the TCP header and data.