Three-way handshake and four waving (attached interview FAQ)

table of Contents

Three-way handshake

TCP connection is established it can be two-way handshake? why?

You can use four-way handshake? why?

The third handshake, if the client's ACK not reach the servers, what will happen?

If you have established a connection, but the client how to do failure occurred?

What initial sequence number is?

Four waving

Why can not the ACK and FIN sent by the server merge into three wave (what is the meaning CLOSE_WAIT state)?

If the second wave ACK server fails to serve clients, what will happen?

What is the significance client TIME_WAIT state is?


Three-way handshake

 

SYN (synchronous): to establish a connection       

ACK (acknowledgement): Confirm

SEQ (sequence number) ACK (confirmation number)

SYN_RCVD即是SYN_Received

 

TCP connection is established it can be two-way handshake? why?

 

Not. The following may occur: The defunct connection request segment has spread to the server .

client first sent a connection request segment is not lost, but in a network node of a long stranded, resulting in delayed to a later time connection release before reaching the server. This in itself is already a failure of the segment. But the server receives this request after the failure of the connection segment, it is mistaken for a new connection request issued by the client again. So it is a confirmation message segments to client, agreed to establish a connection. Do not assume that a "three-way handshake", as long as the server a confirmation, a new connection is established. Now that no client requesting establishment of a connection, and therefore will not ignore the acknowledgment server, it will not send data to the server. But the server thought that the new transport connection has been established, and has been sent to wait for client data. In this way, a lot of resources on the server wasted. A "three-way handshake" approach can prevent this phenomenon. For example, that sort of situation, client does not send a confirmation to confirm the server. Since the server does not receive confirmation, we know that client is not required to establish a connection.

 

 

You can use four-way handshake? why?

can. But it will reduce the efficiency of the transmission.

It refers to a four-way handshake: second handshake: Server sends only ACK and acknowledge number; the initial sequence number and SYN is sent when the Server third handshake; original third handshake protocol becomes the fourth handshake. For optimization purposes, the four-way handshake two or three can be combined.

 

 

The third handshake, if the client's ACK not reach the servers, what will happen?

Since Server ACK is not received acknowledgment, retransmits the previous SYN + ACK (default retransmission five, then automatically close the connection), the Client will receive the retransmission ACK to the Server.

If Client transmits data to the server, the server in response to RST packets.

 

 

If you have established a connection, but the client how to do failure occurred?

Each time the server receives the client's request will reset a timer, the time is usually set to 2 hours, if two hours has not received any data from the client, the server sends a probe segment, after every 75 seconds to send one. If sending 10 consecutive probe packets still did not respond, the server brought out customers considered a failure, and then they close the connection.

 

 

What initial sequence number is?

One of A TCP connection, randomly selected 32-bit sequence number (Sequence Number) as the initial sequence number (Initial Sequence Number, ISN) for transmitting data, such as 1000, to the serial number of the origin, data to be transmitted is No: 1001, 1002 ... when three-way handshake, this initial sequence number sent to the other party B, so that during data transmission, B may confirm what data code is valid; simultaneously during data transmission, a further it was confirmed that each received byte B, if a receives an acknowledgment of the number B (acknowledge number) is 2001, it means the number of data has been successfully accepted 1001-2000 B.

 

 

 

Four waving

 

  • The first wave: Client will FIN is set to 1 , a transmission sequence number seq to the Server ; enter FIN_WAIT_1 state;
  • Second wave: After Server receives FIN, transmitting a ACK = 1, number seq = v, acknowledge number +1 = sequence number of the received segment own; CLOSE_WAIT state enters. In this case the client has no data to send, but still can accept data sent by the server.
  • The third wave: Server sets FIN 1, ACK = 1, a transmission sequence number seq = w, (this time because data may be transferred to a server to a client Client), duplicate acknowledgment ack = u + 1 ,; enter LAST_ACK state;
  • The fourth wave: the Client receives FIN server, enters the TIME_WAIT state; then the ACK is set, transmitting its own sequence number seq, acknowledge number (acknowledgment number) = +1 server sequence number to the server; server receives after confirmation acknowledge number, becomes the CLOSED state, no longer sends data to the client. After the client waits 2 * MSL (maximum segment lifetime) time, but also into the CLOSED state. Four complete wave.

 

Why can not the ACK and FIN sent by the server merge into three wave (what is the meaning CLOSE_WAIT state)?

Because the server receives a client request for a connection is disconnected, some data may be finished, then return to the ACK, indicates that the received request disconnection. After finished until the data retransmission FIN, disconnect the data transfer server client.

 

 

If the second wave ACK server fails to serve clients, what will happen?

The client does not receive acknowledgment ACK, FIN will resend request.

 

 

What is the significance client TIME_WAIT state is?

When the fourth wave, the client sends an ACK to the server may be lost, TIME_WAIT state is used to retransmit ACK packets may be lost. If the Server does not receive ACK, FIN will be retransmitted, if Client received a FIN in 2 * MSL period of time, it will resend the ACK and wait 2MSL again, to prevent Server does not receive ACK and continue to retransmit FIN.

MSL (Maximum Segment Lifetime), refers to a maximum survival time of the network segments, 2MSL is transmitted and a maximum time required for a response. If until 2MSL, Client have not received FIN again, then the Client concluded that ACK has been successfully received, the TCP connection.

 

Published 38 original articles · won praise 6 · views 1904

Guess you like

Origin blog.csdn.net/weixin_43827227/article/details/104248213