Opening a WebSocket Connection
Connect to a WebSocket server.
What Are WebSockets?
WebSockets provide a persistent, full-duplex connection between browser and server over a single TCP connection. Unlike HTTP request/response, either side can send messages at any time — ideal for chat, live feeds, and games.
The ws and wss Schemes
WebSocket URLs use ws:// (plain) or wss:// (TLS-encrypted). Always prefer wss:// in production, just like https.
const url = "wss://example.com/socket";All lessons in this course
- Opening a WebSocket Connection
- Sending and Receiving Messages
- Connection Lifecycle and Errors
- Reconnection Strategies