Today began their own study of Nodejs, see poll, under study
HTTP protocol Description:
The HTTP protocol is a request/response paradigm, and each HTTP response is generated by a corresponding HTTP request; The HTTP protocol is stateless, and there is no relationship between multiple HTTP requests.
In the case of long-connected applications, the client side generally does not actively shut down their connection between the client and the server if the connection is not closed, there will be a problem, as the client connection more and more, the server sooner or later can not carry the time, At this time, the server side needs to take some policies, such as the closure of some long-term no read and write events occurred connection, so as to avoid some malicious connection caused server-side service damage, if the condition is allowed to the client machine for granularity, limit the maximum number of connections per client, This can completely avoid an egg-hurting client from compromising the backend service.
The generation of long and short connections is based on client and server shutdown policies, specific application scenarios with specific strategies, no perfect choice, only the right choice
Application Scenario Differences:
1. General long connection (the pursuit of real-time high scene) for a few client-end to server-end frequent communication , for example: Database connection with long connection, if with short connection frequent communication will cause socket error, and frequent socket Creation is also a waste of resources.
2. HTTP services like Web sites typically use short links (for resource-prone scenarios) because long connections can be resource-intensive for the server, and tens of thousands or even billions of clients, such as Web sites, with short connections can save resources .
Short polling and long polling
and short connections and long connections have essential differences
1. Short polling: repeatedly sending HTTP requests, querying whether the target event is complete, advantages: Writing simple, disadvantage: wasting bandwidth and server resources
2. Long polling: Hold the HTTP request (dead loop or sleep, etc.) on the server until the target time occurs, returning the HTTP response. Pros: No more frequent requests in the absence of messages, disadvantages: writing complex
Application:
Long polling generally used in web IM, im high demand for real-time, HTTP long polling control is always on the server side, and the data is on the server side, so the real-time high;
Like Sina's meager IM, friend net IM and WEBQQ are all implemented with HTTP long polling;
NodeJS's asynchronous mechanism seems to be able to handle the server bottleneck caused by HTTP long polling, which needs to be researched.
HTTP short polling generally used in the real-time requirements are not high, such as Sina's meager unread bar number query is browser-side every time query.
Short polling, long polling, long connections, and short connections in the HTTP protocol