WebSocket
What is it?
WebSocket is a communication protocol that provides full-duplex, bidirectional communication channels over a single TCP connection. Unlike HTTP where clients must repeatedly request data (polling), WebSocket maintains a persistent connection allowing both server and client to send messages at any time. This makes it ideal for real-time applications like chat, live notifications, gaming, and collaborative tools.
Practical example
A chat application establishes a WebSocket connection when a user opens the page using new WebSocket and the server URL. When user A types and sends a message, it travels instantly to the server through the open connection. The server immediately broadcasts this message to user B through their connection. Both users see messages appear in real-time without any page refreshing or repeated API calls.
Test your knowledge
How does WebSocket differ from HTTP?