In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
TCP (Transmission Control Protocol) Transmission Control Protocol
TCP is a host-to-host layer transmission control protocol that provides reliable connection services and uses a three-way handshake to establish a connection:
The bit code is the tcp flag bit, and there are 6 kinds of marks:
SYN (synchronous set up online)
ACK (acknowledgement confirmation)
PSH (push Transport)
FIN (end of finish)
RST (reset reset)
URG (urgent Emergency)
Sequence number (sequence number)
Acknowledge number (confirmation number)
TCP header
TCP establishes a connection
The process of establishing a connection in TCP is shown in the figure above. An opens the service actively and B passively opens the service.
1.B the TCP server process first creates the transmission control block TCB (Transmission Control Block stores some important information in each connection, such as: TCP connection table, pointers to send and receive cached pointers, pointers to retransmission queues, current send and receive serial numbers, etc.), ready to receive connection requests from client processes, and then server processes are in LISTEN state, waiting for client connection requests. If so, respond.
The TCP client process of An also creates a transmission control block, and then sends a connection request message segment to B. at this time, the synchronization bit SYN=1 in the header is selected, and an initial sequence number seq=x is selected. TCP stipulates that SYN message segments (SYN=1 message segments) cannot carry data, but consume a serial number. At this point, the TCP client process enters the SYN-SENT state.
2.B after receiving the connection request message segment, if you agree to establish a connection, send a confirmation to A. In the confirmation paragraph, you should set both the SYN and ACK bits to 1, the confirmation number is ack=x+1, and choose an initial serial number seq=y for yourself. This message segment cannot carry data, and it also consumes a serial number. At this point, the TCP server process enters the SYN-RCVD state.
After receiving the confirmation from B, the 3.TCP client process also gives the confirmation to B. The ACK of the confirmation message section is set to 1, the confirmation number is ack=y+1, and its serial number is seq=x+1. According to the TCP standard, ACK message segments can carry data. However, if you do not carry the data, the sequence number is not consumed, in which case, the sequence number of the next data packet segment is still seq=x+1. At this point, the TCP connection has been established and An enters the ESTABLISHED (established connection) state.
When B receives the confirmation from A, it also enters the ESTABLISHED state.
Why is there a third confirmation?
This is mainly to prevent the invalid connection request message segment from being suddenly transmitted to B, resulting in an error.
Suppose there is no third confirmation from the client. A sends a connection request, but the connection request is lost and does not receive an acknowledgement from B, so A re-issues a request for a connection, and then B receives the request and issues an acknowledgement to establish a connection. After completing the communication, the connection is released and a communication is completed successfully. Although A sent two connection requests, the first one was lost and the second was successful, so there is no invalid connection request message at this time. It is assumed that the connection request message sent by A for a long time due to network problems will not arrive at B until the second communication completes the release of the connection, which is an invalid message, but at this time B thinks that it is another connection request from A. then an acknowledgement is issued, and if there is no third confirmation, the connection is established successfully. Since A did not send the establishment request now, B replied that An ignored it, so he did not communicate with B. however, B kept waiting for A to send him the data, so B foolishly waited for a long time. Wasted his youth (B's resources).
TCP release connection
1. After the end of the data transmission, both sides of the communication can release the connection. Now AMagna B is in the ESTABLISHED state. A first sends the connection release message segment, and stops sending data, and actively closes the TCP connection. A sets the header of the connection release message segment to FIN 1, where the sequence number seq=u,u is equal to the sequence number of the last byte of the previously sent data plus 1. This is An entering FIN-WAIT-1 (stop waiting for 1) state, waiting for B's confirmation. TCP stipulates that FIN message segments consume a sequence number even if they do not carry data.
2. Upon receipt of the connection release message segment, B issues an acknowledgement with the confirmation number ack=u+1, and the message segment's own sequence number is v, which is equal to the sequence number of the last byte of the data sent by B plus 1. Then B enters the CLOSE-WAIT (shutdown wait) state. At this point, the A-> B connection is released, and the TCP connection is in a half-close state, that is, A has no data to send, but if B sends data, A still receives it.
3.An after receiving the confirmation from B, it enters the FIN-WAIT-2 (termination waiting 2) state and waits for the connection release message segment sent by B. If B has no data to send to A, its application process notifies TCP to release the connection. At this point, the connection release message segment sent by B must make FIN=1. Assume that the sequence number of B is w (B may have sent some more data in the semi-closed state). B must also ack=u+1 from the confirmation number that my husband sent last time. At this point, B enters the LAST-ACK state and waits for A to confirm.
4.A upon receipt of the connection release message segment of B, this must be confirmed. In the confirmation message section, set ACK to 1, confirm the number ack=w+1, and your own serial number is seq=u+1 (the previous FIN message segment consumes a serial number). Then enter the TIME-WAIT (time waiting) state. The TCP connection has not been released yet. The time 2MSL set by the time waiting timer (TIME-WAIT timer) must have elapsed before An enters the CLOSED state. (longest message segment life of MSL:Maximum Segment Lifetime)
Why wait in TIME-WAIT?
1. In order to ensure that the last ACK segment sent by A can reach B. This ACK message segment may be lost, so that B in the LAST-ACK state cannot receive confirmation. B will retransmit the FIN+ACK message segment during the timeout, and A will receive the retransmitted FIN+ACK message segment within the 2MSL time, and then A will retransmit the confirmation and restart the timer. At best, the AB enters the CLOSED state normally. If A does not wait for a period of time in the TIME-WAIT state, but releases the connection immediately after sending the ACK message, then the retransmitted FIN+ACK message segment of B will not be received and the acknowledgement message will not be sent again. In this way, B cannot follow the normal steps to enter the CLOSED state.
two。 Prevent invalid connection request messages from appearing in this connection.
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: 246
*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.