How can we understand the "no connection, no status" Features of HTTP?

Source: Internet
Author: User

How can we understand the "no connection, no status" Features of HTTP?

It is an object-oriented protocol at the application layer. HTTP has five main features: 1. Support for customer/Server models; 2. simple and fast; 3. Flexible; 4. No connection; 5. stateless.

No connection

No connection means that only one request is allowed for each connection. After the server processes the customer's request and receives the customer's response, the connection is disconnected. This method can save transmission time.

In the early days, the reason for this was that the HTTP protocol originated from the Internet. Therefore, the server needs to process web pages that are accessible to hundreds of thousands or millions of clients worldwide, but each client (that is, a browser) the Intercommunication between the server and the server is large intermittently (that is, the transmission is sudden and instantaneous), and the Association and divergence of Web browsing results in a low correlation between the two transfers, most channels are actually idle and resource-consuming for no reason. Therefore, HTTP designers intentionally use this feature to design the Protocol as a request to create a connection, release the connection after the request is completed, and release the resource as soon as possible to serve other clients.

Over time, web pages become more and more complex, and many images may be embedded in them. At this time, it is very inefficient to establish a TCP connection for each image access. Later, Keep-Alive was proposed to solve the problem of low efficiency.

The Keep-Alive function keeps the client-to-server connection valid. When a subsequent request is sent to the server, the Keep-Alive function avoids or reestablishes a connection. Most Web servers on the market, including iPlanet, IIS, and Apache, Support HTTP Keep-Alive. This feature is usually useful for websites that provide static content. However, for websites with heavy load, there is another problem here: although it is advantageous to keep the opened connection for the customer, it also affects the performance, because during the pause process, resources that can be released are still in use. When the Web server and Application Server run on the same machine, the impact of the Keep-Alive function on resource utilization is particularly prominent.

In this way, the HTTP connection between the client and the server will be maintained and will not be disconnected (except for the time specified by Keep-Alive and unexpected power failure ), when the client sends another request, it uses the established connection.

Stateless

Stateless means that the Protocol has no memory for transaction processing, and the server does not know the client status. That is, after we send an HTTP request to the server, the server sends data to US based on the request. However, no information is recorded after the request is sent.

HTTP is a stateless protocol, which means that each request is independent and Keep-Alive fails to change this result.

The lack of status means that if subsequent processing requires the previous information, it must be re-transmitted, which may increase the amount of data transmitted each connection. On the other hand, when the server does not need previous information, its response is faster.

The HTTP protocol has its own advantages and disadvantages. The advantage is that it frees the server and does not cause unnecessary connection occupation for each request, the disadvantage is that each request transmits a large amount of duplicate content information.

After the emergence of Web applications that dynamically interact with the client and the server, the stateless HTTP feature severely hinders the implementation of these applications. After all, interaction must be carried forward, A simple Shopping Cart program also needs to know what items the user has selected before. Therefore, the two technologies used to maintain the HTTP connection status came into being. One is Cookie, and the other is Session.

Cookie can maintain the login information to the user's next session with the server. In other words, when accessing the same website next time, the user will find that the user has logged on without having to enter the user name and password (of course, users cannot delete cookies manually ). Some cookies are deleted when the user exits the session, which can effectively protect personal privacy.

The most typical application of Cookies is to determine whether a registered user has logged on to the website. The user may be prompted to determine whether to keep the user information during the next visit to simplify the logon procedures, these are the functions of Cookies. Another important application scenario is "Shopping Cart. Users may select different items on different pages of the same website within a period of time. These information will be written into Cookies so that information can be extracted during the final payment.

A solution opposite to Cookie is Session, which is maintained by the server.

When the client accesses the server, the server sets the Session as needed, stores the Session information on the server, and transmits the SessionId indicating the Session to the client browser. The browser saves the SessionId in the memory, we call it a Cookie with no expiration time. After the browser is closed, the Cookie will be cleared, and it will not exist in the user's temporary Cookie file.

In the future, the browser will add this parameter value for each request. The server will be able to obtain the client data information based on this SessionId.

If the browser of the client closes unexpectedly, the Session data stored on the server is not immediately released, and the data will still exist. As long as we know the SessionId, we can continue to obtain the Session information through the request, because the background Session still exists at this time, of course we can set a Session Timeout time. Once the specified time is exceeded and no client request is sent, the server will clear the Session information corresponding to the SessionId.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.