
Understanding WebSocket Connection (Simple Explanation)
WebSocket is a protocol used for real-time communication between a client and a server . Unlike normal HTTP communication, WebSocket allows continuous, two-way communication over a single connection . 1. WebSocket Connection is Initiated by the Client A WebSocket connection always starts from the client side (browser, mobile app, or any client application). The client sends a request to the server asking to upgrade the connection to WebSocket . Example HTTP request headers: GET /chat HTTP/1.1 Host: example.com Upgrade: websocket Connection: Upgrade If the server supports WebSocket, it responds with: HTTP/1.1 101 Switching Protocols Upgrade: websocket Connection: Upgrade This process is called the WebSocket Handshake . After this handshake, the protocol switches from HTTP to WebSocket . 2. WebSocket is Bi-Directional In traditional HTTP communication: Client → Request Server → Response The server cannot send data unless the client first sends a request. But in WebSocket: Client ⇄ Server
Continue reading on Dev.to Tutorial
Opens in a new tab

