In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >
Share
Shulou(Shulou.com)05/31 Report--
TCP three-way handshake link establishment and four-wave disconnection example analysis, in view of this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and easy way.
One step at a time.
Let's start with a brief introduction to TCP protocol.
TCP (Transmission Control Protocol Transmission Control Protocol) is a connection-oriented, reliable, byte-stream-based transport layer protocol. It is very complicated, but it belongs to the basic skills that both programmers and operators must know.
Object-oriented-the two sides of the connection need to establish a connection in advance before communicating, which is like a real-life phone call, which must be dialed before they can communicate.
Reliable-there are many rules in TCP protocol to ensure the reliability of communication links, including application data separation, retransmission mechanism, header and data verification, sorting of received data, and then to the application layer, the receiver will discard duplicate data, and flow control can be carried out.
TCP data is encapsulated in an IP Datagram in the following format:
Contains: Port number [16bit], serial number [32bit], offset [4bit], Reserved [6bit], flag [6bit], window size (window) [16bit], checksum [16bit], emergency pointer [16bit], TCP option
Here's what you need to note:
TCP packets do not have an IP address, which is a matter at the IP layer, but there are both source and destination ports.
A TCP connection requires four tuples to represent the same connection (src_ip, src_port, dst_ip, dst_port), to be exact, a quintuple, and one is a protocol. But because I'm only talking about the TCP protocol here, I'm only talking about quaternions here.
Sequence Number is the sequence number of a packet and is used to solve the problem of network packet disorder (reordering).
Acknowledgement Number is used by ACK-- to confirm receipt and to solve the problem of not losing packets.
Window, also known as Advertised-Window, also known as sliding window (Sliding Window), is used to solve flow control.
TCP Flag, that is, the type of package, is mainly used to manipulate the state machine of TCP.
URG: emergency pointer is valid
ACK: confirm that the serial number is valid
PSH: the receiver should deliver this message segment to the application layer as soon as possible
RST: rebuilding connection
SYN: synchronization sequence number, which is used to initiate a connection
FIN: the sender completes the sending task (actively shuts down)
Three-way handshake to establish a link
1. The requester (client client) sends a SYN=1 indicating the port of the server to which the customer intends to connect. TCP stipulates that SYN=1 cannot carry data, but consumes a sequence number, so it declares its initial sequence number seq as a random number and assumes that it is seq=x.
two。 The server (server) confirms the client message segment and sets the confirmation sequence number to ACK=x+1. It also requests to connect to the client, send a SYN=1, and the initial seq number is assumed to be seq=y.
3. The client acknowledges the message segment of the server, sends the confirmation sequence number and agrees to establish a connection ACK=y+1 with the server.
These three message paragraphs complete the establishment of the connection. This process is also known as the three-way handshake (three-way handshake)
Break the link with four waves
1. Host 1 (either client or server) sets Sequence Number and Acknowledgment Number to send a FIN message segment to host 2; at this point, host 1 enters the FIN_WAIT_1 state; this means that host 1 has no data to send to host 2
two。 Host 2 receives the FIN message segment sent by host 1 and returns an ACK message segment to host 1, Acknowledgment Number is Sequence Number plus 1; host 1 enters the FIN_WAIT_2 state; host 2 tells host 1 that I have no data to send, so I can close the connection
3. Host 2 sends a FIN message segment to host 1, requesting to close the connection, while host 2 enters the CLOSE_WAIT state
4. Host 1 receives the FIN message segment sent by host 2, sends the ACK message segment to host 2, and then host 1 enters the TIME_WAIT state; host 2 closes the connection after receiving the ACK message segment of host 1; at this time, host 1 still does not receive a reply after waiting for 2MSL, which proves that the Server end has been closed normally, well, host 1 can also close the connection.
At this point, TCP's four breakups are so happily completed.
Establishing a link and breaking a link are shown below:
Let's break down why it's a three-way handshake.
In order to prevent the invalid link request message segment from being suddenly transmitted to the server, an error occurs. Give me a "chestnut".
The first connection request message segment sent by client is not lost, but is stranded at some network node for a long time, so that it is delayed to reach server some time after the connection is released. Originally, this is a message segment that has long been invalid. However, after server received this invalid connection request message segment, it was mistaken for a new connection request sent by client again. A confirmation message was sent to client, agreeing to establish a connection. Assuming that the "three-way handshake" is not used, a new connection is established as soon as the server issues an acknowledgment. Since client does not make a request to establish a connection at this time, it ignores the confirmation of server and does not send data to server. But server thinks that a new shipping connection has been established and has been waiting for data from client. In this way, many of the resources of server are wasted. The above phenomenon can be prevented by using the method of "three-way handshake". For example, in the case just now, client does not issue a confirmation to server's confirmation. Because server did not receive confirmation, he knew that client did not require a connection. "
This makes it clear that the server side has been waiting and wasting resources.
So why four waves?
TCP is a connection-oriented, reliable, byte-stream-based transport layer communication protocol. TCP is in full-duplex mode, which means that when host 1 sends a FIN message segment, it only means that host 1 has no data to send, and host 1 tells host 2 that all its data has been sent; however, host 1 can still accept data from host 2 at this time When host 2 returns an ACK message segment, it already knows that host 1 has no data to send, but host 2 can still send data to host 1; when host 2 also sends a FIN message segment, it means that host 2 has no data to send, it will tell host 1, I have no data to send, and then each other will happily interrupt the TCP connection. If you want to correctly understand the principle of four breakups, you need to understand the state changes in the process of four breakups.
This is the answer to the example analysis of establishing a link with a three-way handshake and breaking a link with four waves in TCP. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel for more related knowledge.
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.