Polling, long polling, long connection, Flash Socket
Release: 2016-08-08 09:22:06
Original
945 people have browsed it
- Polling: The client regularly sends Ajax requests to the server, and the server immediately returns response information and closes the connection after receiving the request.
Advantages: It is easier to write back-end programs.
Disadvantages: Most 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. After receiving the request, the server holds the connection until there is a new message and then returns the response information and closes the connection. After the client processes the response information, it sends a new one to the server. ask.
Advantages: There will be no frequent requests when there is no message.
Disadvantage: Server hold connection consumes resources.
Examples: WebQQ, Hi web version, Facebook IM.
In addition, there is also a distinction between long connections and socket connections:
- Long connection: embed a hidden iframe in the page, set the src attribute of the hidden iframe to a request for a long connection, server side Just continuously input data to the client.
Advantages: Messages arrive immediately and no useless requests are sent.
Disadvantages: Maintaining a long connection by the server will increase overhead.
Example: Gmail chat
- Flash Socket: Embed a Flash program using the Socket class in the page. JavaScript communicates with the server-side Socket interface by calling the Socket interface provided by this Flash program. JavaScript receives the server-side transmission Control the display of the page after the information.
Advantages: Real instant communication, not pseudo-instantaneous communication.
Disadvantages: The client must install the Flash plug-in; it is not an HTTP protocol and cannot automatically traverse the firewall.
Example: Internet interactive game.
The above is an introduction and comparison of the advantages and disadvantages of the four request methods.
Copyright Statement: This article is an original article by the blogger and may not be reproduced without the blogger's permission.
The above has introduced polling, long polling, long connection, and Flash Socket, including all aspects of it. I hope it will be helpful to friends who are interested in PHP tutorials.
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
-
2024-10-22 09:46:29
-
2024-10-13 13:53:41
-
2024-10-12 12:15:51
-
2024-10-11 22:47:31
-
2024-10-11 19:36:51
-
2024-10-11 15:50:41
-
2024-10-11 15:07:41
-
2024-10-11 14:21:21
-
2024-10-11 12:59:11
-
2024-10-11 12:17:31