computer network (application layer)

UDP protocol:

        The UDP protocol provides connectionless, unreliable packet service. A connectionless service means that there is no logical connection between two endpoints exchanging messages. Each message is an independent entity, which is encapsulated in a packet called a datagram.

        The UDP protocol can check whether data is corrupted during transmission, but does not require the sender to retransmit corrupted or lost data.

        For some applications, the advantage of UDP is that it is packet-oriented. It preserves packet boundaries.

        An example is the post office. Each letter is a separate entity with its own sender and receiver. The post office is not responsible if a piece of mail is lost or damaged during delivery.


TCP protocol:

        The TCP protocol provides reliable byte stream transmission. TCP requires two terminals to first establish a logical connection by exchanging some connection establishment packets. This phase is sometimes called a handshake. After the handshake, the two terminals can send data blocks in the form of segments in the direction of each other.

        Continuity of bytes can be detected by counting the number of bytes exchanged. For example, if some bytes are lost or corrupted, the receiver can request to resend those bytes, which makes TCP a reliable protocol. It's like making a phone call. If one party can't hear clearly, you can ask the other party to say it again.

        However, the TCP protocol is not packet-oriented, and it does not preserve packet boundaries.


HTTP protocol (Hypertext Transfer Protocol)

        When we send a request to the server, we first need to establish a connection between the client and the server. Here we have used the TCP service and we know that TCP is a reliable protocol. This means that before any transaction can take place between the client and server, they must establish a connection. After the transaction, the connection should terminate.

        In my previous article about the HTTP protocol, it was mentioned that the HTTP protocol was originally only used to transmit text. In this case, we generally only need to send one request to get all the text. However, with the rapid development of the network, the web page has also Contains other objects such as links, images, videos, etc. . Then at this time, one request cannot complete all tasks. So from here we lead to non-persistent connections and persistent connections.

        Non-persistent connection:

             A simple non-persistent connection would be that we close the connection every time we send a request and get a response. But let's think about it, if the number of requests we want is very, very large, we need to continuously establish and close connections, which will result in a very large time overhead for establishing and closing connections, which is obviously not what we want. screen to see. So persistent connections come in.

        Persistent connection:

                Obviously, a persistent connection only needs to establish a connection once, wait for all requests to be sent and get a response, and then close the connection, which saves a lot of time.

The part about the composition of the message will not be discussed here, you can go directly to the previous blog.

        

Cookie

        Then let's talk about the HTTP protocol. HTTP is a stateless protocol. What does it mean? That is, you send a request, and after getting a response, the connection between the client and the server ends here. Imagine that when we shop on Tmall or JD.com, we need to log in to make a purchase.

        After logging in, we enter the Tmall homepage, and our first request ends here. After that, we see what we want to buy, click it, and because it is stateless, we will find that we need to log in again, because the HTTP protocol does not record your previous login information, which is bad for the stateless protocol place. Therefore, in order to continue to maintain the logged-in state, the smart seniors came up with the cookie. Using cookies, we can keep the logged-in state.

        When we log in for the first time, we send the login information to the server, then the server creates a cookie, includes the cookie in the response and sends it back to the client, so when the client continues to visit the site, the server will know the user You have already logged in, no need to log in again.

        

Guess you like

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