Intern
A persistent two-way connection between the browser and the server is needed for real-time short message exchange. What to choose? WebSocket Server-Sent Events HTTP Long Polling HTTP/2 Server Push
sobes.tech AI
Answer from AI
For persistent two-way communication between the browser and the server, especially for exchanging short messages in real-time, WebSocket is the most suitable.
Explanation:
- WebSocket is a protocol that establishes a persistent connection between the client and the server, allowing both parties to send data at any time without the need for repeated requests.
- Server-Sent Events (SSE) is a one-way channel from the server to the client, not suitable for two-way communication.
- HTTP Long Polling simulates a persistent connection through repeated requests, which is less efficient and has higher latency.
- HTTP/2 Server Push allows the server to send resources to the client without a request, but is not intended for two-way message exchange.
Therefore, WebSocket is chosen for real-time two-way communication.