Basic concepts related to network communication

        The first time I came into contact with network protocols was in the computer network class of the university. After so many years, I did not expect that I would have to regain this knowledge. If I had known earlier in class, I would not have deserted and played mobile games. [It seems a bit late? laughing out loud], well, off topic.

        The famous OSI five-layer protocol is believed to be known by most people, and then the following is the content structure diagram I will probably talk about:

Don't be afraid to see so many agreements, I will try to explain these things with examples bit by bit.

        I believe that most people have used the ftp protocol to download files from an unknown ftp server, something like this

ftp://username:password@FTP server IP or domain name:FTP command port/path/filename

ftp should be a relatively early file transfer protocol. Obviously, this type of protocol is mainly for downloading and uploading files. You can understand it as the file access provided to you by a certain site (the server is actually no different from an ordinary computer). Interface, this protocol contains ip/domain name + port + path/file name. You can imagine a requirement: how can I make others see the contents of the txt file I wrote? ? Similar to HTTP, web browsing and file transfer are usually aggregated together. Here I will explain the use of ftp from top to bottom.

        My understanding is more inclined to the application layer protocol just encapsulates the object, they encapsulate the implementation of file transmission and the implementation of data packet transmission accordingly. The underlying physical layer implementation. Just like the functions implemented by the structure system of mybatis, the functions of jdbc are separated and each part is encapsulated, and some additional features are added to it.

        In the process of transmission, any protocol is stripped layer by layer and analyzed layer by layer, such as domain name----->DNS, ip+port---->TCP packet analysis and so on. The data link layer is mentioned here. This can be imagined as something used by each host in your own local area network for direct communication. If you want to connect to the outside world, you have to add a router and gateway to become ip access. Basically here is the top-level access, and then TCP gives some transmission control functions, and the application layer wraps it into a resource access type that we can easily identify. Domain names are all virtual, and you can access resources by knowing other people's IPs.

        Next, let's focus on the TCP protocol, which has the following characteristics:

        1. Reliable transmission

        2. Connection-oriented

        3. Duplex communication

        To put it bluntly, it is the same as the characteristics of a telephone. Before making a call, you have to dial up first, and you can make a call when you connect. You can also chat with me, right? Each TCP connection contains two endpoints that are abstracted into Sockets, which are composed of an IP address and a port number. Unlike UDP's best-effort delivery, TCP is known as reliable transmission because it implements transmission control.

        In the early days, the reliable transmission of TCP was based on the stop-waiting mechanism + timeout retransmission, but because this method (successfully sent and received one by one in sequence) was too wasteful of channel resources, it finally developed into the now famous sliding window protocol. The sender and receiver that follow this protocol maintain a window value each. The window size is negotiated at the beginning, and then if it encounters network congestion or other conditions, the window will be changed according to a certain algorithm. For the sender, every time it receives a correct confirmation, it can move its window forward, which is actually the interval for preparing the next piece of data. For the receiver, the confirmation given each time the received data is given by The last sequence number received in the correct order, so that all data can be sent correctly. Once the sender's window is full, the sender has to wait for the receiver to give a new window value, which involves flow control.

        The so-called flow control means that what the receiver has received has been soft. The current flow control is to put all the data in the cache first, send a soldier to explore the path first, and if it is found to be feasible, assemble the following data and send it together. (Nagle's algorithm)

        TCP congestion control includes four available algorithms, which are generally used in combination with each other: slow start : that is, the sending window is not so large at the beginning, for example, to 2, and then sends 2 bytes of data to receive confirmation After that, it starts to multiply and increase until a certain threshold threshold is reached, and the congestion avoidance algorithm is used (it's really so bluffing, it's actually i++). If the sender perceives that the network is congested, it can choose to put the new threshold / = 2, set the send window to 1 and start over.

Later, the fast retransmission algorithm appeared (when the receiver receives the out-of-order data, it will send the confirmation before the out-of-order repeatedly, and the sender will re-send the missing data when it receives more than 3 repeated confirmations) and the fast recovery algorithm. (The sending window is set as a new threshold to start the congestion avoidance algorithm directly.) I have to say that these aliases look scary, but the principle is quite simple.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325732632&siteId=291194637