WebSocket
How does a chat room receive new messages in real time?
How does a chat room receive new messages in real time?
?? 1 Ask again each time; messages arriving within the interval wait for the next roundMessages arriving within the polling interval are delayed; shorter intervals cost more requests.
Ordinary requests have fixed delay: Messages arriving within the polling interval wait for the next round; shorter intervals cost more requests.
WebSocket pushes on arrival: The connection stays open, so the server sends new messages immediately; delay depends only on the network.
Both sides can send: It is not just server push: the client can send anytime over the same connection.
The chat room currently polls for new messages every second. Switch to WebSocket: keep the connection open after it is established and push messages as they arrive. Auto-reconnect on disconnection; afterward confirm it is a persistent connection in the Network panel and test that messages resume after a network recovery.