A chat app needs the server to push messages instantly to clients. Most suitable transport?
Options
- Polling the server every 30 seconds
- WebSockets (or Server-Sent Events for one-way push) (Correct option)
- SMTP, the protocol for email delivery
- Plain HTTP/1.0 with a new connection each time
Answer
WebSockets (or Server-Sent Events for one-way push)
Why
Normal HTTP only lets the client ask; the server cannot speak first. Polling ('any news?') every few seconds is wasteful and slow.
A WebSocket keeps one connection open, and both sides can send messages at any time, with very low delay.
Server-Sent Events are a simpler option when only the server needs to push (e.g. live scores).
Remember
Real-time two-way → WebSockets.