TCP - Transmission Control Protocol
This portal offers a variety of tutorials and animations on topics in TCP. In the Internet Protocol Model, TCP is one of the options for the transport layer, the other being UDP. TCP is a connection-oriented, reliable transport layer. It receives a stream of data from the application layer, called a byte stream, which it segments into data units that are called - surprise, surprise - segments. It uses IP as a delivery service, so that IP encapsulates the segments and sends them as datagrams, using IP's unreliable datagram delivery service. However, TCP provides its own reliability mechanisms.
When we say that TCP is "connection-oriented" we mean that there is a procedure that is followed for two communicating end points to exchange data. The TCP connection allows TCP to tailor each byte stream transfer, and maintain the state of that transfer, for each pair of communicating end points. Any given host might have many simultaneous TCP connections, each one having different characteristics, such as the segment size, the timeout (which will be explained), the window size (also to be explained), etc. A specific TCP connection is defined by a socket pair, where a socket is the IP address and port number on one of the communicating points, and the port number identifies the application process on that end point. The port number serves as part of the interface between TCP and the application layer, by identifying which process within a particular host a segment is associated with. The tutorial on the TCP connection explains the TCP connection establishment process, using the three-way handshake, and how connections are terminated.
When TCP sends a segment, it sets a timer, and waits for the other end of the connection to acknowledge receipt of the segment, by indicating the number of the highest byte received - each byte in the byte stream is associated with a byte number. Actually, the acknowledgment contains the number of the next byte in the stream that it expects to receive (and the highest byte received is one less). If an acknowlegment is not received before what is considered a timeout, then the sending end point will retransmit according to a retransmission strategy.
The retransmission timeout (RTO) is a function of a weighted average of the round trip time (RTT) that is recalculated each time a segment is acknowledged. You can learn the theory behind how the RTO is calculated in this tutorial, which also discusses methods for congestion control. You'll learn there that the original calculation of the RTO, as first introduced with TCP, has been modified, to be more sensitive to network conditions. Instructions for an applet that asssists in understanding the original, basic formula, can be found here, and the applet is here. After you have some understanding about the theory, I highly recommend that you try this animated applet (whose instructions are here) that demonstrates the RTT and RTO calculations, based on Karn and Partridge's algorithm. This latter applet allows you to vary a number of parameters, so that you can understand the RTT and RTO calculations in depth, and also see a network in action.
Aside from the retransmit timer that TCP maintains for each connection, there are several other timers that TCP maintains for each connection, one of which is the keepalive timer.
TCP also provides flow control with a sliding window mechanism, demonstrated in the tutorial that you were just linked to.
As you must have concluded, TCP is quite a complex protocol. This portal does not contain information on all of its features. However, the reference page offers some information about good resources, and, of course, the RFCs are the authoritative documentation on TCP. One very important aspect of TCP that was not covered in any of the tutorials or applets linked to from this portal is the TCP header. Like every protocol layer in computer communications, TCP has a header that provides information for the protocol itself to operate and to interface with the application layer, above, and the IP layer, below. By looking at the header and the definition of its fields, you'll see how a lot of the features that you learned about are reflected in the TCP header.
Figure 1, below, shows the TCP header.

Figure 1: TCP Header
You can enhance your understanding of the TCP header, the layering, encapsulation of a TCP segment in an IP datagram, header information, and the three-way handshake by examining TCP segments that were captured with Wireshark. You might already have packet capture software installed on your computer - perhaps you installed it for another RAD University tutorial, such as DNS or SNMP. If not, I strongly recommend that you go to the effort to install a packet capture program, such as Wireshark (which I highly recommend and which is freeware). You can install the software as directed on the website. If you like computer networking and protocols, you'll find it helpful, not just for this tutorial. And, just in case you aren't able to capture any packets just now, you can use this pcap file.
The first three packets in the file contain the three TCP messages that perform the three-way handshake. Figure 2 shows the SYN message sent by the initiator of the connection, typically the client. Notice the value of the initial sequence number, and notice the port number. The port number is 80, which is the well-known port for HTTP (the Hyper Text Transfer Protocol, used for communications with websites).

Figure 2: SYN Segment
Figure 3 shows the SYN,ACK message sent in response by the server. Notice that the server sends its own initial sequence number, and notice that the ACK number is one more than the client's initial sequence number. That is the byte number that is expected to be received next by the server. Notice that both the SYN flag and the ACK flag are set in this second message.

Figure 3: SYN,ACK Segment
Figure 4 shows the last in the sequence for the three-way handshake, the ACK that is sent from the client back to the server. Notice that the ACK number is one more than the server's initial sequence number. You can also notice, as in the previous packet, that Wireshark calculates the RTT. Aside from using this information to examine a network's performance, you can use it to enhance your understanding of the RTT and RTO calculations.

Figure 4: ACK Segment to Complete the Three-Way Handshake
Only now, in the next packets in the capture, will you see that actual application data is transferred. Go ahead and examine the packets that follow on your own; look at the headers, the data, etc. And then try your own packet capture.
For further examination of TCP, you can also look at this demo of the influence of several problematic scenarios on TCP performance and at this tutorial about how the bandwidth of a link is shared by mutiple TCP connections.
Thank you for visiting RAD University. We hope that these TCP tutorials will be helpful.
Debby Koren, "Dean" RAD University
