Three-way handshake CCNA (b) illustrates the four TCP disconnect

When the transport layer of the OSI reference model study, understand TCP (Transmission Control Protocol) is a reliable connection-oriented transport protocol, an unreliable transport protocol UDP (User Datagram Protocol) is connectionless, of course, have both advantages and disadvantages, such as class, the students in this event, TCP protocol equivalent of face to face, UDP protocol equivalent distance learning, online classes, students do not understand the benefits of face to face to tell the teacher, the teacher say it again, until the students understand, this learning method is very reliable. The distance learning students and teachers is not convenient communication, students have made the issue later, but can not see the teacher, learning is not reliable, but the time spent in lectures less than face to face.

So in the network how to achieve this reliable transport it? There must be a mechanism for reliable connection of one kind - four off three-way handshake

TCP header

Before looking at the three-way handshake and waved four times, to know what TCP packet contains something in advance.

1, source IP and destination IP header TCP source port number and destination port number with the IP datagram in a TCP connection is uniquely determined. TCP connection must be established between each other before sending data connection here means: both sides need each other inside information save

2, the main segment of the meaning of the message

  • ID: transmitting data representing a byte stream, TCP ensure orderly transmission, each byte number

  • The acknowledgment number: the next expected sequence number the sender of the received data byte successfully received sequence number plus one. ACK = 1 only if effective.

  • ACK: acknowledgment sequence number flag, ACK = 1 represents a confirmation number is valid, ACK = 0 represents the acknowledgment number of information packets contain

  • SYN: connection request flag number for establishing a connection, SYN = 1 indicates a request connection

  • FIN: end flag, for releasing the connection, the side close to 1 represents the data flow


Three-way handshake

The so-called three-way handshake (Three-Way Handshake) namely the establishment of a TCP connection, refers to the establishment of a TCP connection, the client and the server needs to send a total of three packages to confirm the establishment of the connection. FIG:

Note: wherein synchronization sequence SYN request number, seq sequence number - the number of records transmitted, ctl state
process illustrated:

  1. When the connection start, connection establishment side (Client) sends a SYN packet, and includes its own initial sequence number a;

  2. 连接接受方(Server)收到SYN包以后会回复一个SYN包,其中包含了对上一个a包的回应信息ACK,回应的序号为下一个希望收到包的序号,即a+1,然后还包含了自己的初始序号b;

  3. 连接建立方(Client)收到回应的SYN包以后,回复一个ACK包做响应,其中包含了下一个希望收到包的序号即b+1。


四次断开

所谓四次断开(Four-Way Wavehand)即终止TCP连接,就是指断开一个TCP连接时,需要客户端和服务端总共发送4个包以确认连接的断开。如图:

过程图解:

  1. 首先进行关闭的一方(即发送第一个FIN)将执行主动关闭,而另一方(收到这个FIN)执行被动关闭。

  2. 当服务器收到这个FIN,它发回一个ACK,确认序号为收到的序号加1。和SYN一样,一个FIN将占用一个序号。

  3. 同时TCP服务器还向应用程序(即丢弃服务器)传送一个文件结束符。接着这个服务器程序就关闭它的连接,导致它的TCP端发送一个FIN。

  4. 客户必须发回一个确认,并将确认序号设置为收到序号加1。

为什么建立连接是三次握手,而关闭连接却是四次挥手呢?

这是因为服务端在LISTEN状态下,收到建立连接请求的SYN报文后,把ACK和SYN放在一个报文里发送给客户端。而关闭连接时,当收到对方的FIN报文时,仅仅表示对方不再发送数据了但是还能接收数据,己方也未必全部数据都发送给对方了,己方是否现在关闭发送数据通道,需要上层应用来决定,因此,己方 ACK 和 FIN 一般都会分开发送。

发布了70 篇原创文章 · 获赞 56 · 访问量 1942

Guess you like

Origin blog.csdn.net/qq_43624033/article/details/104108244