Polling, long polling, long connection, socket connection, WebSocket

Source: Internet
Author: User
Tags set time

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. (and each HTTP request and response has full HTTP header information, which increases the amount of data that is transmitted each time)
Example: suitable for small applications.

Long polling: The client sends an AJAX request to the server, The server hold the connection after the request is received, until a new message returns the response information and closes the connection (or closes the connection at a set time-out), and the client processes the response information before sending a new request to the server.
Pros: No more frequent requests in the absence of messages, saving network traffic  , which solves the dilemma that the service side has been tired of accepting requests

example: Webqq, Hi Web, Facebook IM.

Long connection: Embed a hidden iframe in the page, The src attribute of this hidden IFrame is set to the request of a long connection, and the server can continuously input data to the client.


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

WebSocket:

The WebSocket protocol is essentially a TCP-based protocol. In order to establish a WebSocket connection, the client browser first initiates an HTTP request to the server, which differs from the usual HTTP request and contains additional header information, where the additional header information "Upgrade:websocket" indicates that it is an application protocol upgrade The HTTP request, the server side resolves these additional header information and then produces the reply message returns to the client, the client and the server side WebSocket connection is established, the two sides can pass through this connection channel free information, And the connection persists until either the client or the server side actively closes the connection.

Polling, long polling, long connection, socket connection, WebSocket

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.