According to a recent study on the best application-layer protocol approach in mobile Internet with Chinese characteristics, 54chen has made an in-depth investigation on the history of various terms, special record for differentiation.
HTTP protocol history
The first HTTP protocol was born in March 1989.
The first HTTP Protocol version is HTTP 0.9, which is extremely simple because it only allows the client to send the GET request.
The second version of HTTP protocol is HTTP 1.0, until HTTP 1.0 becomes the most important transaction-oriented application layer protocol. This Protocol also establishes and closes a connection for each request/response.
The third version of HTTP is HTTP 1.1, which is currently the most widely used protocol version. From HTTP 1.1, the client establishes a persistent connection with the Web server by default.
Original phase polling
In the early days, because there was no dependency, only the setinterval of JavaScript could be used, and requests were regularly sent to the server.
The advantage is that there is no need to prepare anything special on the server side. It can be processed directly as an HTTP request. The disadvantage is that a large number of requests are wasted.
What is comet?
The Chinese meaning of comet is probably to indicate that this is a request with a long tail.
Like Ajax, comet is a combination of a bunch of Technologies called Comet. (isn't it a term that the Javascript community really like ?).
Initial Stage comet
Cometp belongs to this type (jsonp + IFRAME ).
Frame comet also belongs to this type (JSON + IFRAME ).
Ajax comet also belongs to this type (Ajax)
Http1.1 is a persistent connection, and the chunked encoding mechanism on the server allows partial output of results.
Use the features of http1.1 and then use iframe src to send a URL. Once data exists, use top. func () of JavaScript to notify the browser of the data.
Advantage: It saves more bandwidth than polling. Disadvantage: When you open multiple browsers, multiple connections are occupied. Therefore, you must use the non-blocking HTTP server on the server side. If the network is unstable, it is easy to disconnect.
Improved Version of Comet: Long polling
Network instability is easily interrupted.
After improvement, added the opportunity to initiate a request immediately after each request is returned-long polling.
Advantage: compared with the initial stage, it is not easy to break the connection because of the network. It is the most common solution today. Disadvantages: I can't find any disadvantages. The only drawback is that I use the HTTP protocol. For the TCP layer, I just need to directly connect to and send and receive data.
Bidirectional websocket
As mentioned above, HTML5 comes with a websocket, and Web can also be connected over TCP.
Different browsers have different implementations.
Advantage: underlying connection disadvantage: not supported by many browsers.
Bosh (bidirectional-streams over synchronous HTTP)
This is an extension protocol defined in the XMPP protocol. It can also be attributed to the combination of comet technology.
It also supports the old polling and long polling.
The interaction protocol must be completed in the specific implementation.
Advantage: if the implementation details can be automatically adapted to HTTP 1.0 1.1 disadvantages: The implementation needs to be more complex.
End
Bosh vs comet vs long polling vs polling