As we all know, about TCP/IP, when the rise of the Internet, has been closely related to the life of Internet people, so as a front-end developer, for the knowledge of TCP/IP, whether it needs a deep understanding, the author can tell you without doubt, about TCP/IP knowledge, you really need to know and in-depth understanding.

As a front-end developer, it’s important to know what you need to know about TCP/IP and how to answer it.

Problem summary:

Interviewer: What do you know about TCP/IP?

Little S: Can you be more specific?

Interviewer: OSI seven-tier model versus TCP/IP five-tier model

Little S: A picture is enough to illustrate them

Little S: The following is a description of the three handshakes

  • For convenience, we call the host 172.16.50.72:65076 that initiates the request the client and the host 172.16.17.94:8080 that returns the data the server.
  • First handshake: Establish a connection. The client sends a connection request, sends a SYN packet, and sets seQ to 0. The client then enters the SYN_SEND state and waits for confirmation from the server.
  • Second handshake: The server receives a SYN packet from the client. The SYN segment needs to be acknowledged, and an ACK packet needs to be sent with ACK set to 1. It also sends a SYN request, setting seq to 0. The server sends all the above information to the client, and the server enters the SYN_RECV state.
  • Third handshake: After receiving ACK and SYN packets from the server, the client acknowledges them, sets ACK to 1 and SEQ to 1, and sends an ACK packet to the server. After the ACK packet is sent, the client and server enter the ESTABLISHED state to complete the TCP three-way handshake.

S: The four waves look like this:

  • First wave: The client sends a FIN packet segment to the server, and sets seQ to 160 and ACK to 112. At this point, the client enters the FIN_WAIT_1 state, which means that the client has no data to send to the server and requests to close the connection.
  • Second wave: The server receives the FIN packet from the client and sends an ACK packet with ACK set to 1 and SEQ set to 112 to the client. The server enters the CLOSE_WAIT state. After receiving the ACK packet from the server, the client enters the FIN_WAIT_2 state.
  • Third wave: The server checks whether any data has not been sent to the client. If yes, the server sends the data to the client and then sends a FIN packet. If no, the server directly sends FIN packets to the client. The server is requested to close the connection and enter the LAST_ACK state.
  • Fourth wave: The client receives the FIN packet from the server, sends an ACK packet to the server, sets seQ to 161, ACK to 113, and enters the TIME_WAIT state. After receiving the ACK packet from the client, the server closes the connection. At this point, the client waits for 2MSL and still does not receive a reply, it proves that the Server has been shut down normally, the client can also close the connection.

Interviewer: Let’s talk about the difference between TCP and UDP

Small S:…

  • 1, TCP connection-oriented (for example, to make a phone call to establish a connection); UDP is connectionless, that is, no connection is required before sending data
  • 2. TCP provides reliable service. That is to say, data transmitted through the TCP connection is error-free, not lost, not repeated, and in order to arrive; UDP does its best to deliver, i.e. reliable delivery is not guaranteed
  • 3. TCP byte stream oriented, in fact TCP treats data as a series of unstructured byte streams; UDP is packet oriented

For example, a TCP connection is like a telephone call. There must be an uninterrupted path between the two. The other party will wait until the data reaches the other party, unless the other party directly hangs up the phone. The first words are first come, the last words are last come, there is a sequence.

  • 4. Each TCP connection can be point-to-point only. UDP supports one-to-one, one-to-many, many-to-one and many-to-many interactive communication
  • 5. TCP header cost 20 bytes; The header of UDP has a small overhead of only 8 bytes
  • 6. The logical communication channel of TCP is a full-duplex reliable channel, while UDP is an unreliable channel

conclusion

Do not look down upon these questions, although it is a Baidu search, the answer is the same, but please ask yourself, is not able to express clearly, and let others understand it, so, want to pass the small partner, refuelling, I believe you already know how to answer.