websockets
Skill15 starsChanged 42 days agoMITView on GitHub
Expert WebSockets assistance covering bidirectional full-duplex TCP connections, handshake upgrading, heartbeats/ping-pong, connection state management, and horizontal scaling with Redis Pub/Sub. Use when developing chat applications, live collaboration tools, or multiplayer games.
- Reads credentials
4 other projects use a version of this.
Adopted by
Most recently taken up by
- jars-demo/jars-skillstheir own version, first seen Oct 25, 2026
- emre-guler/websectheir own version, first seen Aug 27, 2026
- Abdox-menara/guard-skillstheir own version, first seen Aug 24, 2026
- ffsshhttiikk/opencode-agents-skillstheir own version, first seen Feb 28, 2026
Other versions4 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 4
- emre-guler/websec★ 2same name
- ffsshhttiikk/opencode-agents-skills★ 2same name
- Abdox-menara/guard-skills★ 0same name
- jars-demo/jars-skills★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository350 other files it gives its agents.
- airflowSkill
- catboostSkill
- claudeSkill
- comfyuiSkill
- cursor-aiSkill
- dalleSkill
- daskSkill
- dbtSkill
- deepseekSkill
- fastaiSkill
- geminiSkill
- github-copilotSkill
- huggingfaceSkill
- jaxSkill
- jupyterSkill
- kerasSkill
- langchainSkill
- lightgbmSkill
- llamaindexSkill
- llamaSkill
- matplotlibSkill
- midjourneySkill
- mistralSkill
- mlflowSkill
- nltkSkill
- numpySkill
- ollamaSkill
- openai-gptSkill
- opencvSkill
- pandasSkill
- perplexitySkill
- plotlySkill
- polarsSkill
- pytorchSkill
- raySkill
- scikit-learnSkill
- seabornSkill
- spacySkill
- sparkSkill
- stable-diffusionSkill
- tensorflowSkill
- vaexSkill
- weights-biasesSkill
- whisperSkill
- xgboostSkill
- api-gatewaySkill
- clean-architectureSkill
- cqrsSkill
- domain-driven-designSkill
- event-drivenSkill
- event-sourcingSkill
- graphqlSkill
- grpcSkill
- hexagonalSkill
- microservicesSkill
- modular-monolithSkill
- monolithSkill
- rest-apiSkill
- sagaSkill
- serverlessSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
1 rule. 0 are common, 1 is distinctive, and 0 are very specific to this project.
0
Common
Most of the 3 edited versions we read keep these.
1
Distinctive
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 157
Use WebSockets for simple unidirectional pushes: Use Server-Sent Events (SSE) if clients only receive data and never send upstream.
“Common” is measured: kept by at least 6 in 10 of the 3 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
WebSockets
WebSockets provide a persistent connection between a client and server that both parties can use to start sending data at any time.
When to Use
- Full-Duplex Real-Time Communication: Applications requiring continuous, low-latency, two-way message exchanges between client and server.
- Live Collaborative Canvases & Documents: Synchronizing multi-user edits, cursor coordinates, and presence indicators (Figma/Google Docs style).
- Multiplayer Online Gaming & Chat: Low-overhead messaging protocols where HTTP request-response overhead would introduce unacceptable lag.
- Financial Trading Desks: Streaming high-frequency bid/ask order book tickers with sub-millisecond updates.
Quick Start
// Server (Node.js with 'ws')
import { WebSocketServer } from "ws";
const wss = new WebSocketServer({ port: 8080 });
wss.on("connection", function connection(ws) {
ws.on("message", function message(data) {
console.log("received: %s", data);
// Echo back
ws.send(`Echo: ${data}`);
});
ws.send("Welcome!");
});// Client (Browser)
const socket = new WebSocket("ws://localhost:8080");
socket.addEventListener("message", (event) => {
console.log("Server says:", event.data);
});Core Concepts
HTTP Upgrade Handshake Protocol
WebSocket connections begin as standard HTTP GET requests and upgrade to raw TCP full-duplex sockets:
GET /chat HTTP/1.1
Host: server.example.com
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==
Sec-WebSocket-Version: 13
HTTP/1.1 101 Switching Protocols
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=Server-Side Socket Management & Rooms
Managing client socket pools and broadcasting to scoped rooms:
import { WebSocketServer, WebSocket } from "ws";
const wss = new WebSocketServer({ port: 8080 });
const rooms = new Map<string, Set<WebSocket>>();
wss.on("connection", (ws, req) => {
const roomId =
new URL(req.url!, "http://localhost").searchParams.get("room") || "global";
if (!rooms.has(roomId)) rooms.set(roomId, new Set());
rooms.get(roomId)!.add(ws);
ws.on("message", (message) => {
// Broadcast message to all clients in the room except sender
for (const client of rooms.get(roomId)!) {
if (client !== ws && client.readyState === WebSocket.OPEN) {
client.send(message);
}
}
});
ws.on("close", () => rooms.get(roomId)?.delete(ws));
});Heartbeat (Ping/Pong) Keepalive
Detects dead connections caused by client drops or silent network disconnects:
// Server heartbeat monitor
const interval = setInterval(() => {
wss.clients.forEach((ws: any) => {
if (ws.isAlive === false) return ws.terminate();
ws.isAlive = false;
ws.ping();
});
}, 30000);
wss.on("connection", (ws: any) => {
ws.isAlive = true;
ws.on("pong", () => {
ws.isAlive = true;
});
});Common Patterns
Horizontal Scaling with Redis Pub/Sub
Problem: Clients connected to different WebSocket server instances cannot exchange messages.
Solution: Distribute broadcast events across server nodes via Redis Pub/Sub.
import { WebSocketServer } from "ws";
import { createClient } from "redis";
const wss = new WebSocketServer({ port: 8080 });
const pub = createClient({ url: process.env.REDIS_URL });
const sub = pub.duplicate();
await Promise.all([pub.connect(), sub.connect()]);
// Subscribe to global channel
sub.subscribe("chat_broadcast", (message) => {
for (const client of wss.clients) {
if (client.readyState === 1) client.send(message);
}
});
// Broadcast client message through Redis
wss.on("connection", (ws) => {
ws.on("message", (data) => pub.publish("chat_broadcast", data.toString()));
});Best Practices
Do:
- Scale Across Nodes with Redis Pub/Sub: Use Redis, NATS, or Kafka to distribute broadcasts across multi-server WebSocket clusters.
- Implement Heartbeats (Ping/Pong): Detect half-open TCP connections by sending periodic pings every 30 seconds.
- Authenticate During the HTTP Handshake: Validate JWT tokens or session cookies in the initial upgrade request before accepting the connection.
- Apply Backpressure & Message Throttling: Limit maximum payload sizes (
maxPayload: 1024 * 1024) and rate limit rapid client messages.
Don't:
- Use WebSockets for simple unidirectional pushes: Use Server-Sent Events (SSE) if clients only receive data and never send upstream.
- Store state on individual server memory alone: Distribute room memberships and sessions using Redis to allow horizontal scaling.
- Transmit uncompressed binary data carelessly: Use compact binary formats like Protobuf or MessagePack for high-frequency coordinate data.
Troubleshooting
| Error | Cause | Solution |
Connection Closed 1006 | Abnormal closure (often network or server crash). | Implement auto-reconnect logic with backoff. |
Load Balancer drops | LB timeout. | Configure Application Load Balancer (ALB) sticky sessions and timeout increase. |
References
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

