伊谢尔伦2017-04-18 10:28:59
First of all, there is a problem with the statement that socket is a long connection. Socket is an intermediate software abstraction layer for communication between the application layer and the TCP/IP protocol family. It can use either the underlying TCP or UDP. Http is based on TCP. The long connections and short connections of the HTTP protocol are essentially the long connections and short connections of the TCP protocol.
Long connections and short connections are relative.
Long connection: After establishing a connection, it is maintained for a period of time. During this period, multiple requests and responses use this connection.
Short connection: Each time a request is made, a connection is established, and the connection is closed when the server responds.
HTTP/1.0 is a short connection, HTTP/1.1 supports long connections, and HTTP/2 has been improved. What is the need behind these improvements? Recommended history of HTTP
PHPz2017-04-18 10:28:59
To be precise, HTTP is based on TCP/IP.
TCP/IP can be long or short, while HTTP mainly uses it as short.
HTTP can also be long, as long as the server and browser do not close the link all the time. This method was once popular to achieve real-time server notification (search http comet to find out).
PHP中文网2017-04-18 10:28:59
HTTP just "does not require" long connections. You can keep it alive or close the socket immediately after the transmission is completed. There is no problem.