In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "what is the meaning of HTTP long connection and short connection respectively". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what does HTTP long connection and short connection mean respectively?"
1. The relationship between HTTP protocol and TCP/IP protocol
The long connection and short connection of HTTP are essentially TCP long connection and short connection. HTTP belongs to the application layer protocol, which uses TCP protocol at the transport layer and IP protocol at the network layer. IP protocol mainly solves the problem of network routing and addressing, while TCP protocol mainly solves how to reliably transmit data packets above the IP layer, so that the receiver on the network receives all the packets sent by the sender, and the order is consistent with the sending order. TCP protocol is reliable and connection-oriented.
two。 How to understand that HTTP protocol is stateless
The HTTP protocol is stateless, which means that the protocol has no memory ability for transactions, and the server does not know what the client state is. That is, there is no connection between opening a web page on a server and the last time you opened a web page on that server. HTTP is a stateless connection-oriented protocol, stateless does not mean that HTTP can not maintain TCP connections, let alone that HTTP uses the UDP protocol (connectionless).
3. What are long connections and short connections?
Short connections are used by default in HTTP/1.0. In other words, every time the client and server perform a HTTP operation, a connection is established, and the connection is interrupted at the end of the task. When a client browser accesses a HTML or other type of Web page that contains other Web resources (such as JavaScript files, image files, CSS files, etc.), every time such a Web resource is encountered, the browser will re-establish a HTTP session.
From HTTP/1.1, long connections are used by default to maintain the connection characteristics. Using the long-connected HTTP protocol, this line of code is added to the response header:
Connection:keep-alive
In the case of a persistent connection, when a web page is opened, the TCP connection used to transmit HTTP data between the client and the server will not be closed, and when the client accesses the server again, it will continue to use this established connection. Keep-Alive does not stay connected permanently, it has a hold time, which can be set in different server software (such as Apache). The realization of persistent connection requires that both client and server support persistent connection.
The long connection and short connection of HTTP protocol are essentially the long connection and short connection of TCP protocol.
The operation procedure of a short connection during the operation of a short connection is to establish a connection-data transmission-close the connection. The procedure for establishing a connection-data transfer-closing a persistent connection is to establish a connection-data transfer. (keep the connection). Data transfer-when to close a connection, when to use a long connection, a short connection?
Long connections are mostly used for frequent operations, point-to-point communication, and the number of connections should not be too many. Each TCP connection requires a three-step handshake, which takes time. If each operation is connected first, then the processing speed will be much lower, so it will continue to open after each operation, and the OK will be sent directly during the second processing. There is no need to establish a TCP connection. For example, database connections use long connections, frequent communication with short connections will cause socket errors, and frequent socket creation is also a waste of resources.
Http services like WEB sites generally use short links, because long links will consume certain resources for servers, while thousands or even hundreds of millions of clients with short connections like WEB sites will save some resources. If long links are used, and there are thousands of users at the same time, it can be imagined if each user occupies a connection. Therefore, the amount of concurrency is large, but each user needs to use short connection when there is no need for frequent operation.
Thank you for your reading, the above is the content of "what is the meaning of HTTP long connection and short connection respectively". After the study of this article, I believe you have a deeper understanding of what HTTP long connection and short connection mean respectively, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.