What is WebSocket and how is it different from HTTP?+
HTTP is a request-response protocol - the client asks, the server answers, then the connection closes. WebSocket creates a persistent, bidirectional connection - either side can send messages at any time. Ideal for chat, live dashboards, gaming, and real-time collaboration.
What is the difference between ws:// and wss://?+
ws:// is unencrypted WebSocket, like HTTP. wss:// is WebSocket over TLS, like HTTPS. Always use wss:// in production - ws:// transmits data in plain text and is blocked on HTTPS pages (mixed content).
How do I authenticate a WebSocket connection?+
WebSocket doesn't natively support HTTP headers during the upgrade handshake. Common patterns: pass a token as a query parameter (wss://api.example.com?token=xyz), send an auth message immediately after connecting, or use cookie-based auth.
What causes WebSocket connection errors?+
Common causes: server not running or wrong port, CORS policy blocking the upgrade, SSL certificate errors for wss://, firewall blocking WebSocket ports, proxy not supporting WebSocket protocol upgrade.