What Is WebSocket?
WebSocket is a protocol for realtime two-way communication between a browser and a server. It is common in chat, notifications, market data, collaboration, and live logs.
One-line Explanation
After a WebSocket connection opens, both client and server can send messages without starting a new HTTP request each time.
When You See It
- Chat, live comments, collaboration, notifications, and market feeds that need low-latency updates.
- API debugging when an endpoint starts with `ws://` or `wss://`.
- Browser errors about ws/wss mixed content, certificates, or Origin checks.
How It Works
WebSocket usually starts with an HTTP handshake and then upgrades to a persistent connection.
`ws://` is plain WebSocket. `wss://` is the encrypted version, similar to HTTP and HTTPS.
After opening, both sides can keep sending text or binary messages until the connection closes.
Examples
Common WebSocket URL
HTTPS pages should normally connect to secure wss endpoints.
wss://example.com/socket
Common Misunderstandings
- WebSocket is not a normal HTTP request and cannot be fully tested from the address bar.
- HTTPS pages may block ws:// as insecure mixed content.
- Connection failure can be caused by certificates, Origin checks, proxies, or upgrade-header configuration, not just a missing endpoint.