Loading...
Loading...
Expert in real-time communication systems, including WebSockets, Socket.IO, SSE, and WebRTC.
npx skill4agent add 404kidwiz/claude-supercode-skills websocket-engineerWhat is the communication pattern?
│
├─ **Bi-directional (Chat/Game)**
│ ├─ Low Latency needed? → **WebSockets (Raw)**
│ ├─ Fallbacks/Auto-reconnect needed? → **Socket.IO**
│ └─ P2P Video/Audio? → **WebRTC**
│
├─ **One-way (Server → Client)**
│ ├─ Stock Ticker / Notifications? → **Server-Sent Events (SSE)**
│ └─ Large File Download? → **HTTP Stream**
│
└─ **High Frequency (IoT)**
└─ Constrained device? → **MQTT** (over TCP/WS)| Scale | Architecture | Backend |
|---|---|---|
| < 10k Users | Monolith Node.js | Single Instance |
| 10k - 100k | Clustering | Node.js Cluster + Redis Adapter |
| 100k - 1M | Microservices | Go/Elixir/Rust + NATS/Kafka |
| Global | Edge | Cloudflare Workers / PubNub / Pusher |
Upgrade: websocketConnection: Upgradesecurity-engineer*npm install socket.io redis @socket.io/redis-adapterserver.jsconst { Server } = require("socket.io");
const { createClient } = require("redis");
const { createAdapter } = require("@socket.io/redis-adapter");
const pubClient = createClient({ url: "redis://localhost:6379" });
const subClient = pubClient.duplicate();
Promise.all([pubClient.connect(), subClient.connect()]).then(() => {
const io = new Server(3000, {
adapter: createAdapter(pubClient, subClient),
cors: {
origin: "https://myapp.com",
methods: ["GET", "POST"]
}
});
io.on("connection", (socket) => {
// User joins a room (e.g., "chat-123")
socket.on("join", (room) => {
socket.join(room);
});
// Send message to room (propagates via Redis to all nodes)
socket.on("message", (data) => {
io.to(data.room).emit("chat", data.text);
});
});
});ulimit -n 65535/etc/security/limits.confsysctl -w net.ipv4.ip_local_port_range="1024 65535"wsusers = []random(0, 10s)socket.on('message', () => { heavyCalculation(); })