WebSocket

WebSocket

WebSocket is a protocol for two-way communication between client and server over a single, long-lived TCP connection.

About WebSocket

The WebSocket protocol enables both client and server to send messages to each other without making new HTTP requests for each message. After an initial HTTP handshake the communication channel is upgraded to WebSocket, and the connection remains open for bidirectional use.

This is especially useful for real-time applications like chat, games, stock tickers, or IoT solutions where it’s important to push data from the server to the client instantly - without the client polling for updates. Because WebSocket uses ports commonly open for HTTP (80 and 443) and works with many proxy and firewall setups, it’s a practical choice for modern web infrastructure.

In practice this means you initiate a connection using ws:// or wss:// (secure over TLS), send an HTTP GET request with Upgrade: websocket, and the server replies with 101 Switching Protocols - after that you can send text or binary frames freely in both directions as long as the connection stays open. The relationship between HTTP and WebSocket is primarily in the handshake; afterward the protocol operates as a standalone full-duplex channel.