websocket-implementation by aj-geddes/useful-ai-prompts
npx skills add https://github.com/aj-geddes/useful-ai-prompts --skill websocket-implementation构建可扩展的 WebSocket 系统,用于实时通信,具备适当的连接管理、消息路由、错误处理和水平扩展支持。
最小化工作示例:
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 适配器用于水平扩展
const redisClient = redis.createClient();
const { createAdapter } = require("@socket.io/redis-adapter");
io.adapter(createAdapter(redisClient, redisClient.duplicate()));
// 连接管理
const connectedUsers = new Map();
// ... (完整实现请参阅参考指南)
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
references/ 目录下的详细实现:
| 指南 | 内容 |
|---|---|
| Node.js WebSocket 服务器 (Socket.IO) | Node.js WebSocket 服务器 (Socket.IO) |
| 浏览器 WebSocket 客户端 | 浏览器 WebSocket 客户端 |
| Python WebSocket 服务器 (aiohttp) | Python WebSocket 服务器 (aiohttp) |
| 消息类型和协议 | 消息类型和协议 |
| 使用 Redis 进行扩展 | 使用 Redis 进行扩展 |
每周安装量
170
代码仓库
GitHub 星标数
121
首次出现
2026年1月21日
安全审计
安装于
opencode144
codex139
gemini-cli135
cursor130
claude-code128
github-copilot124
Build scalable WebSocket systems for real-time communication with proper connection management, message routing, error handling, and horizontal scaling support.
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)
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 |
Weekly Installs
170
Repository
GitHub Stars
121
First Seen
Jan 21, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykWarn
Installed on
opencode144
codex139
gemini-cli135
cursor130
claude-code128
github-copilot124
Lark Drive API 使用指南:飞书云文档、Wiki、表格 Token 处理与文件管理
23,400 周安装