198k views
1 vote
What is Long Polling, and how does it work, and why would you use it?

A. Long Polling is a method for server-client communication where the server sends updates at regular intervals, and it's used for low-latency, real-time applications.
B. Long Polling is a technique for optimizing database queries, reducing server load, and improving caching.
C. Long Polling is a method of server-client communication where the client sends updates at regular intervals, and it's used for high-latency, batch-processing applications.
D. Long Polling is a security mechanism to prevent unauthorized access to server resources.

User DomJack
by
8.2k points

1 Answer

4 votes

Final answer:

Long Polling is a server-client communication method where the server holds a request open until updates are available. It's used to create real-time experiences in web applications when technologies like WebSockets are not feasible. It is an intermediate solution between traditional polling and persistent connections.

Step-by-step explanation:

Long Polling is a technique used in server-client communication where the client makes a request to the server and the server holds the request open until it has data to send. When the server finally has new information, it responds to the request and closes the connection. The client immediately makes a new request, and this process continues indefinitely. This could be visualized as a series of held-open requests where the server waits to send a response until an update is available or a timeout occurs.

This approach allows the creation of applications that can update in real-time without having to refresh the web page. Long Polling is favored in situations where real-time updates are crucial, such as in chat applications or live data feeds, and where other more real-time technologies like WebSockets may not be feasible.

Therefore, Long Polling serves as an intermediate solution between traditional polling, which can create unnecessary network traffic and server load, and more modern solutions which may require a persistent two-way connection.

User Ivan Kruglov
by
7.6k points