当前位置:网站首页>TCP interview

TCP interview

2022-06-26 11:13:00 Unable to type 314

TCP interview

Preposition

tcp The following brain map is not a big problem in dealing with the interview

Brain map in hand , Don't panic

 Insert picture description here

wireshark Grab the bag

Use wireshark Grab the bag and remember tcp Three handshakes , Four waves

1.springboot Get ready

@RestController
public class HelloController {
    

    @GetMapping("/")
    public String hello() {
    
        return "";
    }

}

Start project

2.cmd perform curl command

curl localhost:8080

3. Observe wireshark The change of

image-20220625013721360

Relevant interview questions

Why? TCP When you connect, it's 3 Time ?2 Can't you do it again ?

Because we need to consider the problem of packet loss when connecting , If you just shake hands 2 Time , In the second handshake, if the confirmation message segment sent by the server to the client is lost , At this time, the server is ready to send and receive data ( It can be understood that the server has successfully connected ) According to the , But the client has not received the confirmation message from the server , So the client doesn't know if the server is ready ( The client is not connected successfully ), In this case, the client will not send data to the server , It also ignores the data sent by the server .

If it's three handshakes , Even if there is a packet loss, there will be no problem , For example, if you shake hands for the third time, the client sends a confirmation ack Message lost , The server has not received the confirmation within a period of time ack The message will enter again

Line second handshake , That is, the server will resend SYN Message segment , After receiving the retransmitted message segment, the client will send a confirmation to the server again ack message .

Why? TCP When you connect, it's 3 Time , When it was closed, it was 4 Time ?

Because it can only be disconnected when the client and server have no data to send TCP. And the client sends out FIN Message can only ensure that the client has no data sent , The server does not know whether the data is sent to the client . And the server receives the client's FIN After the message can only reply to the client a confirmation message to tell the client that the server has received your FIN Message , But my server still has some data to send out , After these data are sent, the server can send it to the client FIN message ( Therefore, it is not possible to combine the confirmation message with the

FIN The message is sent to the client , It's here one more time ).

TCP and UDP difference

It is not allowed to combine the confirmation message with the

FIN The message is sent to the client , It's here one more time ).

TCP and UDP difference

image-20220625013929023

原网站

版权声明
本文为[Unable to type 314]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/177/202206261023535007.html