TCP is a connection-oriented transport layer protocol that provides reliable full-duplex data transmission. TCP is part of the TCP/IP protocol stack. In a connection-oriented environment, a connection is established between both ends before the transfer of information can begin. TCP breaks messages into segments, reassembles them at the destination, and resends anything that is not received. TCP supplies a virtual circuit between end-user applications.
It exhibits the following key features:
- Transmission Control Protocol (TCP) corresponds to the Transport Layer of OSI Model.
- TCP is a reliable and connection-oriented protocol.
- TCP offers:
- Stream Data Transfer.
- Reliability
- Efficient Flow Control
- Full-duplex
- TCP offers connection-oriented end-to-end packet delivery.
- TCP ensures reliability by sequencing bytes with a forwarding acknowledgement number that indicates to the destination the next byte the source expect to receive.
- It retransmits the bytes not acknowledged with in specified time
TCP Services
TCP offers following services to the processes at the application layer:
- Stream Delivery Service
- Sending and Receiving Buffers
- Bytes and Segments
- Full Duplex Service
- Connection Oriented Service
- Reliable Service
TCP Header Format:
TCP uses only a single type of protocol data unit, called a TCP segment. The header is shown in Figure. Because one header must serve to perform all protocol mechanisms, it is rather large, with a minimum length of 20 octets.
The following are the definitions of the fields in the TCP segment:
- Source port – Number of the port that sends data
- Destination port – Number of the port that receives data
- Sequence number – Number used to ensure the data arrives in the correct order
- Acknowledgment number – Next expected TCP octet
- HLEN – Number of 32-bit words in the header
- Reserved – Set to zero
- Code bits – Control functions, such as setup and termination of a session
- Window – Number of octets that the sender will accept
- Checksum – Calculated checksum of the header and data fields
- Urgent pointer – Indicates the end of the urgent data
- Option – One option currently defined, maximum TCP segment size
- Data – Upper-layer protocol data
- Code Bits or Flags (6 bits).
- URG: Urgent pointer field significant.
- ACK: Acknowledgment field significant.
- PSH: Push function.
- RST: Reset the connection.
- SYN: Synchronize the sequence numbers.
- FIN: No more data from sender.
TCP Handshake
- Step 1 (SYN) : In the first step, client wants to establish a connection with server, so it sends a segment with SYN(Synchronize Sequence Number) which informs server that client is likely to start communication and with what sequence number it starts segments with
- Step 2 (SYN + ACK): Server responds to the client request with SYN-ACK signal bits set. Acknowledgement(ACK) signifies the response of segment it received and SYN signifies with what sequence number it is likely to start the segments with
- Step 3 (ACK) : In the final part client acknowledges the response of server and they both establish a reliable connection with which they will start eh actual data transfer
The steps 1, 2 establish the connection parameter (sequence number) for one direction and it is acknowledged. The steps 2, 3 establish the connection parameter (sequence number) for the other direction and it is acknowledged. With these, a full-duplex communication is established.