Learn VisualLearn API

Long Polling, SSE, and WebSocket Receive Updates in Different Ways

Long polling is an ordinary request. The server holds its response until it has an update to report, and the client sends a new request as soon as it receives the response. As a result, it looks like one slow request repeated in a loop. This approach avoids the waste of sending a request every few seconds and getting a mostly empty response.

SSE keeps one connection open, and the server keeps pushing events down it. The client only receives events and never sends anything back over that connection.

WebSocket also keeps one connection open, but data flows in both directions, and the client and the server can each send at any time. Chat-like uses need this, and long polling and SSE, which only carry updates from the server to the client, can't provide it.

GOAL

Compare long polling, SSE, and WebSocket by how long each connection is held open and whether data flows in one direction or both.

A chat application needs both to receive new messages instantly and to send a message the moment the user types one, all without repeatedly opening new connections. Which fits?