About websocket-implementation
A skill for designing scalable WebSocket systems with connection management, message routing, and error handling. It is intended for developers building real-time communication, with guidance on horizontal scaling and implementation patterns.
Key features
- 01Connection lifecycle management
- 02Message routing and error handling
- 03Horizontal scaling support
- 04Node.js and Python server guides
- 05Browser client and protocol guides
Use cases
- 01Building real-time chat
- 02Sending live notifications
- 03Creating collaborative editing tools
- 04Streaming events to clients
Install
Copy the command and run it in a terminal.
$
npx skills add https:/ / github.com/ aj-geddes/ useful-ai-prompts --skill websocket-implementationAfter installing, type/websocket-implementationin Claude Code to confirm it loaded.
Bundled files
References and scripts installed along with SKILL.md.
references/browser-websocket-client.mdmessage-types-and-protocols.mdnodejs-websocket-server-socketio.mdpython-websocket-server-aiohttp.mdscaling-with-redis.mdscripts/validate-api.shtemplates/api-scaffold.yamlDetails
From the project READMEWebSocket Implementation
Table of Contents
Overview
Build scalable WebSocket systems for real-time communication with proper connection management, message routing, error handling, and horizontal scaling support.
When to Use
- Building real-time chat and messaging
- Implementing live notifications
- Creating collaborative editing tools
- Broadcasting live data updates
- Building real-time dashboards
- Streaming events to clients
- Live multiplayer games
Quick Start
Minimal working example:
const express = require("express");
const http = require("http");
const socketIo = require("socket.io");
const redis = require("redis");
const app = express();
const server = http.createServer(app);
const io = socketIo(server, {
cors: { origin: "*" },
transports: ["websocket", "polling"],
reconnection: true,
reconnectionDelay: 1000,
reconnectionDelayMax: 5000,
reconnectionAttempts: 5,
});
// Redis adapter for horizontal scaling
const redisClient = redis.createClient();
const { createAdapter } = require("@socket.io/redis-adapter");
io.adapter(createAdapter(redisClient, redisClient.duplicate()));
// Connection management
const connectedUsers = new Map();
// ... (see reference guides for full implementation)
Reference Guides
Detailed implementations in the references/ directory:
| Guide | Contents |
|---|---|
| Node.js WebSocket Server (Socket.IO) | Node.js WebSocket Server (Socket.IO) |
| Browser WebSocket Client | Browser WebSocket Client |
| Python WebSocket Server (aiohttp) | Python WebSocket Server (aiohttp) |
| Message Types and Protocols | Message Types and Protocols |
| Scaling with Redis | Scaling with Redis |
Best Practices
✅ DO
- Implement proper authentication
- Handle reconnection gracefully
- Manage rooms/channels effectively
- Persist messages appropriately
- Monitor active connections
- Implement presence features
- Use Redis for scaling
- Add message acknowledgment
- Implement rate limiting
- Handle errors properly
❌ DON'T
- Send unencrypted sensitive data
- Keep unlimited message history in memory
- Allow arbitrary room/channel creation
- Forget to clean up disconnected connections
- Send large messages frequently
- Ignore network failures
- Store passwords in messages
- Skip authentication/authorization
- Create unbounded growth of connections
- Ignore scalability from day one
Comments
Markdown supported