Transmission Control Protocol provides reliable, ordered, and error-checked delivery of a stream of octets between applications running on hosts communicating over an IP network. Major Internet applications such as the World Wide Web, email, remote administration and file transfer rely on TCP.
Applications that do not require reliable data stream service may use the User Datagram Protocol (UDP), which provides a connectionless datagram service that emphasizes reduced latency over reliability.
TCP protocol operations may be divided into three phases.
- Connections must be properly established in a multi-step handshake process (connection establishment) before entering the data transfer phase.
- data transfer
- termination closes established virtual circuits and releases all allocated resources.
A TCP connection is typically managed by an Operating System through a Application Programing Interface (API) that represents the local Endpoint for communications, the Internet socket. During the lifetime of a TCP connection the local end-point undergoes a series of state changes:
- LISTEN (server) represents waiting for a connection request from any remote TCP and port.
- SYN-SENT (client) represents waiting for a matching connection request after having sent a connection request.
- SYN-RECEIVED (server) represents waiting for a confirming connection request acknowledgment after having both received and sent a connection request.
- ESTABLISHED (both server and client) represents an open connection, data received can be delivered to the user. The normal state for the data transfer phase of the connection.
- FIN-WAIT-1 (both server and client) represents waiting for a connection termination request from the remote TCP, or an acknowledgment of the connection termination request previously sent.
- FIN-WAIT-2 (both server and client) represents waiting for a connection termination request from the remote TCP.
- CLOSE-WAIT (both server and client) represents waiting for a connection termination request from the local user.
- CLOSING (both server and client) represents waiting for a connection termination request acknowledgment from the remote TCP.
- LAST-ACK (both server and client) represents waiting for an acknowledgment of the connection termination request previously sent to the remote TCP (which includes an acknowledgment of its connection termination request).
- TIME-WAIT (either server or client) represents waiting for enough time to pass to be sure the remote TCP received the acknowledgment of its connection termination request. According to RFC 793 a connection can stay in TIME-WAIT for a maximum of four minutes known as two MSL (maximum segment lifetime).
- CLOSED (both server and client) represents no connection state at all.
Connection establishment#To establish a connection, TCP uses a three-way handshake. Before a client attempts to connect with a server, the server must first bind to and listen at a port to open it up for connections: this is called a passive open. Once the passive open is established, a client may initiate an active open. To establish a connection, the three-way (or 3-step) handshake occurs:
- SYN-SENT: The active open Request is performed by the client sending a SYN-SENTchronize to the server. The client sets the segment's sequence number to a random value A.
- SYN-ACK: In response, the server replies with a SYN-ACK (Synchronize-Acknowledgement). The Acknowledgement number is set to one more than the received sequence number i.e. A+1, and the sequence number that the server chooses for the packet is another random number, B.
- ACK: Finally, the client sends an ACKnowledgement back to the server. The sequence number is set to the received acknowledgement value i.e. A+1, and the Acknowledgement number is set to one more than the received sequence number i.e. B+1.
More Information#There might be more information for this subject on one of the following:
- Challenged Networks
- Internet Protocol Suite
- RFC 0793
- RFC 793
- Transport Layer
- Two Generals Problem