socket-io
/socket-io
Socket.IO real-time bidirectional communication. Rooms, namespaces, acknowledgments, middleware, scaling with Redis adapter, and TypeScript types. USE WHEN: user mentions "Socket.IO", "socket.io", "real-time chat", "live updates", "bidirectional WebSocket", "rooms", "namespaces" DO NOT USE FOR: SSE (server-sent events) - use `sse`; WebRTC - use `webrtc`; raw WebSocket without Socket.IO - use framework WS skills
- Author
- claude-dev-suite ↗
- Repository
- claude-dev-suite ↗
- Licence
- MIT
- Last repository change
- 21.10.2026
Assessment and security
- Files in this package
- 1
- Scripts
- 0
- HTML comments
- 0
- URLs in SKILL.md
- 0
No signals detected. Repository changed on 21.10.2026, without references to retired models or APIs.
MIT, open: use and modify while retaining author attribution.
What it does and when to use it
Socket.IO real-time bidirectional communication. Rooms, namespaces, acknowledgments, middleware, scaling with Redis adapter, and TypeScript types. USE WHEN: user mentions "Socket.IO", "socket.io", "real-time chat", "live updates", "bidirectional WebSocket", "rooms", "namespaces" DO NOT USE FOR: SSE (server-sent events) - use `sse`; WebRTC - use `webrtc`; raw WebSocket without Socket.IO - use framework WS skills
Triggers from the description
Original author description
Socket.IO real-time bidirectional communication. Rooms, namespaces, acknowledgments, middleware, scaling with Redis adapter, and TypeScript types. USE WHEN: user mentions "Socket.IO", "socket.io", "real-time chat", "live updates", "bidirectional WebSocket", "rooms", "namespaces" DO NOT USE FOR: SSE (server-sent events) - use `sse`; WebRTC - use `webrtc`; raw WebSocket without Socket.IO - use framework WS skills
How it works
- Server Setup
- Client Setup
- Scaling with Redis Adapter
- React Hook
- Anti-Patterns
- Production Checklist
SKILL.md preview
---
name: socket-io
description: |
Socket.IO real-time bidirectional communication. Rooms, namespaces,
acknowledgments, middleware, scaling with Redis adapter, and TypeScript types.
USE WHEN: user mentions "Socket.IO", "socket.io", "real-time chat",
"live updates", "bidirectional WebSocket", "rooms", "namespaces"
DO NOT USE FOR: SSE (server-sent events) - use `sse`;
WebRTC - use `webrtc`; raw WebSocket without Socket.IO - use framework WS skills
allowed-tools: Read, Grep, Glob, Write, Edit
---
# Socket.IO
## Server Setup
```typescript
import { Server } from 'socket.io';
import { createServer } from 'http';
const httpServer = createServer(app);
interface ServerToClientEvents {
message: (data: { user: string; text: string; timestamp: number }) => void;
userJoined: (user: string) => void;
}
interface ClientToServerEvents {
sendMessage: (text: string, callback: (status: 'ok' | 'error') => void) => void;
joinRoom: (room: string) => void;
}
const io = new Server<ClientToServerEvents, ServerToClientEvents>(httpServer, {
cors: { origin: process.env.CLIENT_URL },
});
// Authentication middleware
io.use((socket, next) => {
const token = socket.handshake.auth.token;
try {
socket.data.user = verifyToken(token);
next();
} catch {
next(new Error('Authentication failed'));
}
});
io.on('connection', (socket) => {
console.log(`${socket.data.user.name} connected`);
socket.on('joinRoom', (room) => {
socket.join(room);
socket.to(room).emit('userJoined', socket.data.user.name);
});
socket.on('sendMessage', (text, callback) => {
const message = { user: socket.data.user.name, text, timestamp: Date.now() };
io.to('general').emit('message', message);
callback('ok');
});
socket.on('disconnect', () => {
console.log(`${socket.data.user.name} disconnected`);
});
});
```
## Client Setup
```typescript
import { io, Socket } from 'socket.io-client';
const socket: Socket<ServerToClientEvents, ClientToServerEvents> = io(API_URL, {
auth: { token: getAuthToken() },
reconnection: true,
reconnectionDelay: 1000,
});
socket.on('connect', () => console.log('Connected'));
socket.on('message', (data) => addMessage(data));
socket.on('connect_error', (err) => console.error(err.message));
// With acknowledgment
socket.emit('sendMessage', 'Hello!', (status) => {
if (status === 'error') showError('Failed to send');
});
```
## Scaling with Redis Adapter
```typescript
import { createAdapter } from '@socket.io/redis-adapter';
import { createClient } from 'redis';
const pubClient = createClient({ url: process.env.REDIS_URL });
const subClient = pubClient.duplicate();
await Promise.all([pubClient.connect(), subClient.connect()]);
io.adapter(createAdapter(pubClient, subClient));
```
## React Hook
```tsx
function useSocket(room: string) {
const [messages, setMessages] = useState<Message[]>([]);
useEffect(() => {
socket.emit('joinRoom', room);
socket.on('message', (msg) => setMessages((prev) => [...prev, msg]));
return () => { socket.off('message'); };
}, [room]);
const send = (text: string) => socket.emit('sendMessage', text, () => {});
return { messages, send };
}
```
## Anti-Patterns
| Anti-Pattern | Fix |
|--------------|-----|
| No authentication | Use `io.use()` middleware with JWT |
| Broadcasting to all instead of rooms | Use `socket.to(room).emit()` |
| No reconnection handling | Enable reconnection, show UI indicator |
| Single server without adapter | Use Redis adapter for horizontal scaling |
| No acknowledgments for critical events | Use callback parameter for delivery confirmation |
## Production Checklist
- [ ] Authentication middleware on connection
- [ ] Redis adapter for multi-server deployment
- [ ] Reconnection with exponential backoff
- [ ] Room-based message scoping
- [ ] Connection state UI indicator
- [ ] Rate limiting on message events
Versions
The database has no other skills named socket-io.
Database snapshot: 13.11.2026 · package version 9c31c49db4a9 (SHA-256 digest of the entire package)
Downloads in the last 30 days: 1 · ranking
Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.
Similar skills
- 100socketio
Socket.IO 4.x covering namespaces, rooms, acknowledgements, adapters, scaling, connection state recovery, middleware, TypeScript types, and multi-server deployment. Use for \"Socket.IO\", \"socket.io\", \"rooms\", \"namespaces\", \"Socket.IO adapter\", \"Redis adapter\",… - 100websocket-engineer
Use this agent when implementing real-time bidirectional communication features using WebSockets, Socket.IO, or similar technologies at scale. - 100socketio
Socket.IO is a Node.js library for bidirectional, event-based real-time communication between browsers (or other clients) and a server, with WebSocket transport, HTTP long-polling fallback, automatic reconnection, rooms and namespaces. Use when a user asks to build a chat, live… - 100websocket-engineer
Use when building real-time communication systems with WebSockets or Socket.IO. Invoke for bidirectional messaging, horizontal scaling with Redis, presence tracking, room management. - 100nestjs-real-time
Implement WebSocket gateways with Socket.io and Server-Sent Events endpoints in NestJS. Use when building chat features, live feeds, or choosing between WebSocket and SSE for real-time communication. - 100nestjs-websocket
WebSocket integration for NestJS using Socket.IO. Covers gateways, rooms, authentication guards, exception filters, and Redis adapter for scaling. USE WHEN: user mentions "NestJS WebSocket", "NestJS gateway", "Socket.IO NestJS", "real-time NestJS", "NestJS chat", "WebSocket…