CompTIA Network+ Certification Guide
上QQ阅读APP看书,第一时间看更新

TCP

When you send a letter using your local postal service, have you ever wondered whether your letter reaches the destination successfully, whether it was prioritized within the processing system of the mail service for delivery, or whether you would receive confirmation  that your letter was delivered successfully? Consider that, in a network, there are the same concerns with devices. If one device sends a datagram to another device, whether on the same LAN or a remote network, what reassurance is given for the guarantee of the datagram (message) between the sender and the receiver?

TCP defined by RFC 793 is a connection-oriented protocol that operates on the Transport Layer of both the OSI reference model and the TCP/IP protocol stack. It is designed to provide reliable transportation of the datagrams over a network. It provides reassurance by initializing a three-way handshake before communicating data between the sender and the receiver. Let's imagine there are two devices that want to communicate and use TCP to ensure their messages are delivered successfully. Let's use a simple analogy to further explain the TCP three-way handshake; we have two devices, Bob and Alice. Bob wants to exchange data with Alice but needs to ensure the data being sent is successfully delivered, so Bob decides to use the TCP to guarantee the delivery.

Bob initializes the TCP three-way handshake by sending a TCP Synchronization (SYN) packet to Alice indicating he wants to establish a session or connection. Alice, upon receiving the SYN packet, responds to Bob indicating she also wants to establish a session and acknowledges receipt of the SYN packet using a TCP Synchronization/Acknowledgment (SYN/ACK) packet. Bob, upon receiving the TCP SYN packet from Alice, responds with a TCP Acknowledgement (ACK) packet. Now the TCP three-way handshake is established, data can be exchanged between the two devices; with each datagram sent across the session between Bob and Alice, an ACK packet will be sent to confirm successful delivery of the message:

What if Bob sends a message to Alice and Bob does not receive an ACK packet from Alice? In this situation, Bob would retransmit the data again after certain intervals until an ACK packet is sent back to Bob. Another question you may have is—how does TCP terminate a session gracefully? Each device sends a TCP Finish (FIN) packet to each other, indicating they would like to terminate the session:

Furthermore, if we use a network protocol analyzer tool, such as Wireshark (www.wireshark.org), we can see the packet composition of each datagram passing across the network. The following exhibit is a capture using Wireshark during the writing of this book to demonstrate the TCP three-way handshake:

Another benefit of using TCP is its ability to reassemble packets that may have arrived in an out-of-order fashion at the destination.