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.
Advantages: In the absence of a message without frequent requests, the cost of small resources.
Cons: Server hold connections consume resources, return data order is not guaranteed, difficult to manage maintenance.
Example: WEBQQ, HI Web version, Facebook IM.
Long connection: embed a hidden iframe in the page, set the SRC attribute of the hidden IFRAME to a request for a long connection, or use a XHR request, and the server can continuously enter data to the client.
Advantage: The message arrives immediately, does not send the useless request, the management is also relatively convenient.
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 difference between the fall, the long fall, the long connection, the flash socket