Article 1: Long and Short connections in HTTP

Source: Internet
Author: User
Welcome to reprint, reprint please indicate the source of http://blog.csdn.net/yankai0219/article/details/8208776 1. persistent connection and short connection:Persistent connection: the client establishes a connection with the server. After the connection is established, the client continues to send and receive packets. In this mode, communication connections always exist. This method is usually used for P2P communication. Short connection: the client and server communicate with each other only when sending and receiving packets. The connection is closed immediately after the transaction is completed. This method is usually used for one-to-multiple-point communication. C/s communication. Ii. Operation Process of persistent connection and short connection:The procedure for a short connection is to establish a connection-data transmission-to close the connection... to establish a connection-data transmission-to close a persistent connection, follow these steps: establish a connection-data transmission... (keep connection )... data transmission-close connection Iii. Time to use persistent connection and short connection:
Transient connectionIt is often used for frequent operations, point-to-point communication, and the number of connections cannot be too large. Three handshakes are required for the establishment of each TCP connection, and four handshakes are required for the disconnection of each TCP connection. If a connection needs to be established for each operation, the processing speed will be reduced. Therefore, after each operation, you can directly send data during the next operation without establishing a TCP connection. For example: Persistent connection for database connectionIf short connections are used for frequent communication, the socket errors may occur. Frequent socket creation is a waste of resources. Transient connection: HTTP Services for web sites generally use short connections. Because persistent connections consume resources for servers.. Connections to thousands or even hundreds of millions of clients such as web sites frequently use short connections to save some resources. Imagine how much pressure the server would be under if we were using persistent connections with thousands of users and each user had a connection. So A large number of concurrent connections, but each user does not need to perform frequent operations.. In short, the choice of persistent connection and short connection depends on the needs. Persistent connections and short connections are generated by the closing policies adopted by the client and server. Specific policies are used in specific application scenarios. There is no perfect choice but a proper choice.Summary of HTTP persistent connections and short connections: The difference between long connections and short connections mainly lies in The closing policies adopted by the client and server are different.. After a connection is established, the connection is closed after only one data transmission is performed, the persistent connection will transmit data multiple times after the connection is established until the connection is closed (the connection is closed through the connection: Closed header field in the persistent connection ). The difference between the two closing policies leads to the advantages of persistent connections: 1) Enabling and disabling fewer TCP connections saves CPU time and memory. 2) reduces the number of packets caused by TCP enabling and network blocking. Both Different application scenarios. Transient connections are mostly used for frequent operations and point-to-point communication, and the number of connections cannot be too large. Persistent connections are used for database connections.

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.