Five features of the 1.HTTP protocol
1) Support client/server mode
2) Simple and fast
3) Flexible
4) No connection
Each connection processes only one request, and the server finishes processing the customer's request and is disconnected after being answered by the customer.
5) No Status
The protocol does not log server client status.
2. Two ways to keep the HTTP connection state
1) Cookies
When accessing a unified Web site, information can be written to cookies to facilitate the extraction of information between different pages.
2) Session
The session is saved on the server, and the SessionID that identifies the session is passed to the client browser, saved in a cookie, and the cookie is cleared when the browser is closed.
Browser each request will be added to this parameter value, the server according to this SessionID, can obtain the client's data information.
3. What is an HTTP long connection, short connection
Long connections of HTTP, short connections are essentially TCP long connections, short connections.
In http/1.0, a short connection is used by default.
That is, the browser and the server each HTTP operation, the establishment of a connection, the end of the task to disconnect. This way, if a Web page contains other Web resources, such as JavaScript files, image files, CSS files, etc., you need to establish a connection.
From http/1.1, a long connection is used by default. We can see that the response header has such a line of code: connection:keep-alive
When a Web page is opened, the TCP connection between the client and the server for transmitting HTTP data does not close, and if the client accesses the Web page on the server again, it will continue to use the established connection.
4. Long connection short connection operation process
The operation steps for a short connection are:
Establish connection--data transfer--close connection ... Establish connection--data transfer--close connection
The procedure for long connections is:
Establish connection--data transfer ... (Keep connected) ... Data transfer--close connection
5. Advantages and disadvantages of long connection short connection
Long connections eliminate the more TCP setup and shutdown operations, reducing waste and saving time. For customers who frequently request resources, they are more suitable for long connections.
If the connection between client and server is not closed, there will be a problem, as the client connects more and more, the server will be unable to carry out the time, the server side needs to take some policies, such as the shutdown of a long time no read and write events connection ; Limit the maximum number of long connections per client.
Short connections are simpler to manage for servers, and connections that exist are useful. However, if customer requests are frequent, time and bandwidth will be wasted on TCP setup and shutdown.
6. Long connection short Connection use occasion
Long connections are used for frequent, point-to-point communication, and the number of connections cannot be too many. such as a database connection.
HTTP services like Web sites are generally short-connected, because long connections consume a certain amount of resources for the server, and tens of thousands or even billions of clients, such as Web sites, use short connections to save resources, if they are long connected, and have thousands of users at the same time. If each user occupies a connection, then you can imagine it. Therefore, the concurrency is large, but each user does not need frequent operation of the case with a short connection good.
HTTP long connections and short connections