Predecessor to WebSockets
Explore the historical background of WebSockets.
Long polling, a real-time alternative
WebSocket is not the only real-time communication technology used in your applications. We may have restrictions in our application’s environment that prevent using a WebSocket, such as having very inconsistent client connectivity due to our application’s user profile. Since this course was published, there may even be a newly emerged technology that provides even better two-way web communication. It is crucial for our application maintenance that we do not design it solely around WebSocket usage.
Note: We have a WebSocket-powered application, not a WebSocket application.
A less efficient but still viable real-time communication layer is HTTP long polling. Phoenix ships with long polling support out-of-the-box, which means we can quickly add it to our server when necessary. We can even run WebSockets in tandem with HTTP long polling. Let’s look at how long polling works, where it’s helpful, and where it can fall short.
What is long polling?
HTTP long polling is a technique that uses standard HTTP to send data to a client asynchronously. This fits the requirement of a real-time communication layer that can send (long poll response) and receive (client request) data from a client. Long polling is the most frequently used predecessor to WebSockets, predating several years. This means that the technique is very stable, despite its disadvantages.
Get hands-on with 1200+ tech skills courses.