Polling : The client periodically sends an AJAX request to the server, returning the response information and closing the connection as soon as the server receives the request.
Pros: It's easier to write back-end programs.
Cons: Half of the requests are useless, wasting bandwidth and server resources.
Example: suitable for small applications.
Long Polling: The client sends an AJAX request to the server, the server receives the request and hold the connection until a new message returns the response information and closes the connection, and the client finishes processing the response and sends a new request to the server.
Advantage: No more frequent requests in the absence of messages.
Disadvantage: Server hold connections consume resources.
Example: WEBQQ, HI Web version, Facebook IM.
In addition, there is a distinction between long connections and socket connections:
Long connection : Embed a hidden iframe in the page, set the src attribute of this hidden iframe to a long connection request, and the server can continuously input data to the client.
Advantage: Instant message arrives without unwanted request.
Disadvantage: The server maintains a long connection that increases overhead.
Example: Gmail Chat
Flash Socket: Embed a flash program JavaScript using the socket class within the page to communicate with the server-side socket interface by invoking the socket interface provided by this flash program. JavaScript controls the display of the page after it receives information from the server side.
Pros: Realize real instant communication, not pseudo-instant.
Disadvantage: The client must have a Flash plugin installed, a non-HTTP protocol, and cannot automatically traverse the firewall.
Example: Network interactive game.
The above is the introduction of four kinds of request methods and comparison of advantages and disadvantages.
Polling and long polling