Skip to content

Commit f47ef82

Browse files
feat: add web sockets
1 parent ebca277 commit f47ef82

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
INFO: WebSockets
3+
A WebSocket is a protocol enabling full-duplex, bi-directional,presistent communication over a single TCP connection. Unlike HTTP's request-response model, it keeps the connection open, letting both client and server send messages anytime.
4+
5+
INFO: Key Points
6+
1. Begins with an HTTP Upgrade handshake using ws:// or wss://
7+
2. After upgrade, message frames carry data in both directions
8+
3. Ideal for real-time apps: chat, live dashboards, gaming, IoT
9+
*/
10+
11+
// Usage
12+
const ws = new Socket("wss://example.com/socket");
13+
14+
ws.onopen = () => { ws.send("Hello Server"); };
15+
ws.onmessage = e => console.log("From server:", e.data);
16+
ws.onclose = e => console.log("Connection closed");
17+
ws.onerror = err => console.error("Error:", err);

0 commit comments

Comments
 (0)