Polling and long polling

Source: Internet
Author: User

    1. 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.

    2. 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:

    1. 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

    2. 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

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.