In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
TCP/IP state machine
In the TCP layer, there is a FLAGS field with the following identities: SYN, FIN, ACK, PSH, RST, URG.
Among them, the first five fields are useful for our daily analysis.
What they mean is:
SYN means to establish a connection
FIN means to close the connection
ACK indicates response
PSH indicates that there is a DATA data transfer (there is a real TCP packet content being delivered)
RST indicates that the connection is reset (it is not until after FIN that the connection is 1)
The main purpose of the three-way handshake is to initialize the initial value of Sequence Number. That's an and b in the picture above. In the future data communication, this number is increased in the sending order on the client side and reorganized in the incremental order on the server side to ensure that the data received by the application layer will not be out of order because of network problems.
Establish a stable two-way connection, requiring at least 3 communications
Take Zhang San calling Li Si as an example
call
Hello, Li Si, can you hear me [seq=0]?
Lisa: well, I can hear you [ack=seq+1], can you hear me [seq=0]?
I can hear you [ack=seq+1]
1. Both parties can take the initiative to close at the same time, or one party can take the initiative to close and drive the other to close passively, but usually one party takes the initiative and the other is passive (as shown in the figure, client active server passive), so it seems to be the so-called four waves. If both sides actively disconnect at the same time, both parties will enter the CLOSING state, then reach the TIME_WAIT state, and finally time out and go to the CLOSED state
2. Why is it that establishing a connection protocol is a three-way handshake, while closing a connection is a four-way handshake?
TCP is full-duplex, and each direction needs to be turned off separately (that is, sending a FIN). Sending a FIN means that there is no data flow in one direction, but it can be received.
This is because when the SOCKET in the LISTEN state of the server receives the connection request of the SYN message, it can send ACK and SYN (ACK responds and SYN synchronizes) in a single message. But when you close the connection, when you receive a notification from the other party's FIN message, it only means that the other party has no data to send to you. However, all your data may not be sent to the other party, so you may not shut down SOCKET immediately, that is, you may need to send some data to the other party, and then send the FIN message to the other party to show that you agree to close the connection now, so the ACK message and FIN message here are sent separately in most cases.
Take Zhang San hanging up the phone to Li Si as an example
Zhang San: I have to hang up now [FIN]. Seq=x]
Lisa: OK [ack. Seq=x+1]
Lisa: I hung up [fin,seq=b,ack=X+1] too.
Zhang San: OK [ack,seq=b+1]
Analysis of three-way handshake
The HTTP protocol is based on TCP links.
We visit a web page. Using wireshark to analyze the process of establishing a connection with a three-way handshake in TCP
The filtering rules of Wireshark show only the data we need
(ip.src==10.108.15.43 and ip.dst==10.108.16.3) or (ip.src==10.108.16.3 and ip.dst==10.108.15.43)
1. Seq=0 (add 1 to the value of seq for each packet sent)
2. Seq+1 received by ack=
TCP stream:
Wave four times:
1. The TCP protocol stipulates that the shutdown operation is initiated by sending a FIN segment (FIN is set). At the same time, the FIN message segment also contains ACK of the recently received data.
2. The receiver acknowledges the FIN and sends the ACK=k+1 to the sender
3. The receiver sends the connection closure to the upper application program, and the application initiates the connection closure operation. At this time, the receiver becomes active by passively closing the connection, and sends a FIN message segment to the sender. The sequence number of the message is L (you can also see here that the ACK sequence number was sent in the previous step, because ACK does not occupy the sequence number.
So the serial number of the FIN here is also L).
4. After the sender receives the FIN and sends back the ACK to the receiver, the TCP connection is terminated. If the FIN is lost, the sending end of the FIN needs to resend the FIN until the ACK is received.
Relative to the state machine
12 state machines:
Welcome to learn: state Machine and retransmission Mechanism of TCP
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.