WebSocket
WebSocket is a full-duplex communication protocol that enables a persistent
connection between the client and server, allowing both to send and receive
messages in real time.
Key Features:
Full-Duplex Communication: Both the client and server can send messages to each
other independently.
Persistent Connection: Once established, the connection stays open, reducing the
overhead of repeatedly establishing new HTTP connections.
Binary or Text Data: WebSocket supports both binary and text-based communication.
Custom Protocol: While it starts with an HTTP/HTTPS handshake, it upgrades the
connection to the WebSocket protocol (e.g., ws:// or wss:// for secure WebSocket).
How It Works:
The client sends an HTTP request to the server with an Upgrade header to establish
a WebSocket connection.
If the server accepts the upgrade, the connection switches from HTTP to WebSocket.
After the connection is established, messages can flow in both directions until the
connection is closed.
Use Cases:
Chat applications.
Online gaming.
Financial tickers (e.g., stock price updates).
Collaborative tools (e.g., Google Docs).