How the server pushes Comet long polling is different from the way ordinary Ajax constantly requests

Source: Internet
Author: User

When we want to display some data in the browser in real time, how?

There are many ways to implement, the simplest is to set an interval, Ajax constantly send requests, this way the most obvious flaw whether or not new data will always send the request, and this interval if set long, timeliness is too poor, If the interval is set short, each client is constantly sending a large number of requests that affect server performance

Another is the use of server push technology, based on the way of long polling:

At the outset, this is also in the constant request server side, and ordinary Ajax constantly request what is the difference? This is a process that has not yet been known for long polling. In-depth study, found the difference is very big

The approximate process for long polling is:ClientSend the request via AJAX, fetch the data on the server side, if there is no data then the thread waits, there is data to wake up the thread and return the data, close the connection,ClientAjax callbacks, whenXMLHttpRequest's readystateAt 4, continue to request the server and establish the connection again.

So it seems that there is no timeliness in the way of long polling, and server-side access to data, there may be more than one data, The client can retrieve all the information on the current server at once, thus improving the efficiency.

How the server pushes Comet long polling is different from the way ordinary Ajax constantly requests

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.