用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/G1Joshi/Agent-Skills --skill websockets命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
基于 SOC 职业分类
正在显示 SKILL.md
| name | websockets |
| description | WebSockets real-time bidirectional communication. Use for real-time features. |
WebSockets provide a persistent connection between a client and server that both parties can use to start sending data at any time.
// 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();
});
ws.();
});
// Client (Browser)
const socket = new WebSocket("ws://localhost:8080");
socket.addEventListener("message", (event) => {
console.log("Server says:", event.data);
});
Starts as an HTTP Request (Upgrade: websocket). If server accepts (101 Switching Protocols), the specific TCP connection becomes a WebSocket connection.
Essential to keep connections alive through proxies/firewalls that drop idle TCP connections.
A library that adds features on top of raw WebSockets: Auto-reconnection, Rooms, Fallback to HTTP Long-Polling.
Users subscribe to channels (e.g., chat_room_1). The server routes messages only to sockets in that channel (using Redis for scaling across multiple servers).
Do:
Don't:
| 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. |