tcp agreement with close_wait time_wait State Meaning

Title Description

1. What is a three-way handshake, four wave? Why respectively to three and four?

2.tcp agreement, close_wait time_wait state and represent what meaning, why should these two states designed to solve the problem?

Why 3.time_wait to wait 2MSL

4. troubleshoot problems usually met a lot close_wait how to deal with?

 

Answers

1. First, the positioning of the TCP protocol is to be understood, from about copy wikipedia defined: Transmission Control Protocol ( English: T ransmission  C ontrol  P rotocol , abbreviation: TCP ) is connection-oriented, reliable , based on the byte stream of the transmission layer communication protocol, the IETF is the RFC 793 definition. In a simplified computer network OSI model in which the fourth layer is completed the functions specified in the transport layer. User Datagram Protocol (UDP) transmission protocol is another important same layer. 

 

And TCP is a bi-directional full-duplex transmission protocol, and then explained in more detail later in this.

 

Then talk to you about what tcp six flags:

  • SYN(synchronous) Synchronize sequence numbers to initiate a connection
  • ACK(acknowledgement) The ackowledgement number is valid
  • PSH(传送) The receiver should pass this data to the application as soon as possible
  • FIN(finish结束) The sender is finished sending data.
  • RST(reset重置) Reset the connection
  • URG(urgent) The URGENT POINTER field contains valid data

image.png

 

image.png

 

step1: client-side attempt to establish a connection, sending a tcp packet, this tcp packet header in the SYN flag is 1, and it will randomly generated ISN (initial sequence number) as the sequence number of the packet header stuffed inside, this when the client side into the SYN-SENT state

step2: server termination by the client sends a request and returns the message has been received indicating that the request to establish the connection, and at the same time try to establish server-to-client connections. Therefore, this time the header in the SYN and ACK flag is set to 1 at the same time, and the server side generates its own ISN as a sequence number, and the client side was ack number seq number + 1.

step3: client receiving the message, which is connected client-> server-side has been established, it means ready to send data from the client side to the server side, but ciient end must also send a message to the server end ack, ack this time flag is 1, ack number of server-side seq number + 1, when subjected to the terminating server message indicates that the connection is established.

 

Why then answer the three-way handshake: First tcp protocol is reliable, so by ack mechanisms to ensure that the sender can confirm whether the recipient has received the message. Secondly, we mentioned earlier tcp is bi-directional full-duplex, which means what? It means that once the connection is established, client and server can take the initiative to take the initiative to send a message like each other, and when sending data but also able to accept data. So step1 + step2 actually recommended to connect client-> server-side, and step2 + step3 establish a server-> client connections. In fact, here we have understood, step2 fact, for reasons of efficiency and to step 1 to step 2, at the time when the return ack packets incorporates a connection is established, so the 4-step and three-step order.

 

image.png

step1: client sends fin packet server, in this case seq number of u, client terminal to enter state fin_wait_1

step2: server termination message by transmitting ack packet Client, seq number at that time is v, server enters close_wait end state (generally this time will inform application layer related operations), this time into fin_wait_2 Client state, Client- > server has been connected to close

step3: application layer after waiting for completion of the relevant operation, the server side also sends fin package, attempts to close server-> client connection, the server-side case enters last_ack state (see a lot of places to say at this time will bring a client-side interrupt ack, this I understand nothing necessary? I do not know if anyone can help me explain)

step4: client side to the server side returns ack, and enters a state time_wait for 2msl

 

Why four wave: in fact, the general process with almost three-way handshake, the only difference among the two-step and do not step into, and there is no reason to step should be to close the application layer a little time to do the preparatory work.

 

2.close_wait time_wait above and should have a say, close_wait represents received a request to close the connection of the other application, but this time you may application layer as well as things to do, otherwise these two steps can be combined into one step, directly into the state last-ack. And when completed step4, server-side reasons may be because the network does not receive ack, this time will repeat step3, if the client did not enter time_wait end state but directly closed, will result in server end can not be closed properly. Meanwhile, since the messaging network delay is present, enters the closed state immediately after sending the ACK If, then immediately establish a new connection on the same Port, there may receive messages on the remaining connection time may guide unpredictable actuation of various abnormal.

 

3. Consider the worst case, step4client sent to the server, this time the message was lost, this step is the longest occupation 1msl, server-side judge after the message is lost, repeat step3 resend fin to the client, this step is the longest occupation 1msl, so add up to 2msl.

 

4. In fact, this question was not very good, we need to understand a lot of what close_wait harm. Because linux is assigned to a user's file handle is limited (usually 1024), or if time_wait colse_wait two states is kept, these channels will be has always played and will soon be reported too many open files in system (this is os-level error), then the gg. So first of all there are a lot of conscious close_wait is dangerous, then according to the above mentioned, close_wait by an object initiate disconnection, and you have not returned ack, then you will have been maintained in close_wait state (in general are client-side and server-side connection is established, then the client ends forget close, server-side began to take the initiative to disconnect, but the client side is not responding, and then hang it up). Then problem usually occurs first on the machine can wait netstat -na | awk '/ ^ tcp / {++ S [$ NF]} END {for (a in S) print a, S [a]}', look connected case (though there is a general monitor, then this step can be omitted). Then netstat -an, look at what are connected time_wait state, according to ip server-side theory can determine which connection is out, and then is to see this piece of code, there is no place to forget the release of the connection.

 

Postscript: reality may be more complex scenarios, such as out of order messages, such as the loss of all the circumstances, the above only discuss the process forward, want to dig words you may also need to consider more exceptions process.

 

references:

1.https://zh.wikipedia.org/wiki/%E4%BC%A0%E8%BE%93%E6%8E%A7%E5%88%B6%E5%8D%8F%E8%AE%AE

2.http://telescript.denayer.wenk.be/~hcr/cn/idoceo/tcp_header.html

 

Guess you like

Origin www.cnblogs.com/chuanheng/p/tcp.html