Long Polling, Sockets, and Server Events Flashcards
(10 cards)
What are three popular methods for a client to interact with a web server?
Long-polling, web sockets, and server-side events.
What happens during an HTTP request?
- Client opens connection and requests data from server.
- Server calculates and constructs response.
- Server sends request back through opened connection.
What is polling? What about AJAX polling?
Polling is the concept of repeatedly requesting data from the server, typically for updates. AJAX polling (asynchronous JavaScript and XML) is a popular approach for polling.
Describe a typical polling workflow (AJAX etc.).
- Client opens a connection and requests data (typically via HTTP).
- Client will issue requests at regular intervals.
- Server will respond with any available data.
- Process will repeat to continually update from the server.
What’s a key problem related to polling?
Depending on the frequency, it can create a lot of unnecessary requests/empty responses in cases where no new data is available.
What is long-polling? How does it differ from normal polling?
Long-polling works similar to a normal poll with the expectation the response may take a while. In cases where the response is empty, the server will simply wait to respond until there is new data.
Long-polls are typically bound to timeouts to determine when to “give up”.
What are websockets? What do they provide?
Web sockets allow full duplex (bidirectional) commutation over a single TCP connection.
How are websocket connections established?
They are established through a handshake process from the client-server.
What’s a benefit of the websocket protocol?
The protocol reduces overhead by not requiring each request/operation to be verified by the client, which expedites communication in real-time.
What are Server-Sent Events (SSEs)? What are they good for?
SSEs are persistent connections established by the client to a server that allow the server to send data to the client (one direction).
They are best suited in systems where the client needs real-time updates or frequently changing data from the server.