What is the difference between Http and TCP for TCP long connections and short connections?

Source: Internet
Author: User
Tags socket error

The HTTP protocol, the Hypertext Transfer Protocol (hypertext Transfer Protocol), is the foundation of Web networking and one of the most commonly used protocols for mobile networking, an application built on the TCP protocol. Because HTTP is actively releasing the connection after each request ends, the HTTP connection is a "short connection", which requires constant connection requests to the server to maintain the client program's online status. HTTP is the application-layer protocol, and TCP is the Transport Layer protocol (below the application layer).
one, long connection and short connection:Long Connection: The client and the server to establish a connection, the connection after the establishment of continuous open, and then send and receive messages. This means that the communication connection is always present. This approach is commonly used for peer-to-peer communication.
Short Connection: A communication connection is made between client and server each time a message is sent and received, and disconnected immediately after the transaction is completed. This approach is often used in a point-to-multipoint communication. c/S communication.
two, long connection and short connection operation process:the procedure for a short connection is to establish a connection--data transfer--to close the connection ... Establish connection--data transfer--close connection;
the operation of the long connection is: Establish a connection-data transmission ... (Keep connected) ... Data transfer--close connection
three, long connection and the use of short connection time:long connections are used for frequent, point-to-point communication, and the number of connections can not be too many cases. Each TCP connection is established with a three-time handshake, and each TCP connection disconnects four times. If each operation to establish a connection and then the operation of the processing speed will be reduced, so each time the operation of the next operation to send data directly, no longer establish a TCP connection. For example: Database connection with a long connection, if a short connection with frequent communication will cause a socket error, frequent socket creation is also a waste of resources.
Short connections: HTTP services for Web sites are generally short-connected. Because a long connection consumes a certain amount of resources for the server. Thousands or even billions of clients, such as Web sites, connect more resources with short connections. Imagine if all with a long connection, and at the same time with thousands of users, each user has a connection, it can be imagined how much pressure on the server. Therefore, the concurrency is large, but each user does not need to operate frequently in the case of short connections.
in summary: The choice of long connections and short connections depends on the requirements.

What is the difference between Http and TCP for TCP long connections and short 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.