WebSocket Implementation

WebSocket Implementation

Guides a coding agent in building real-time WebSocket systems with connection management, message routing, Socket.IO and Redis-based horizontal scaling.

Skill files8 files

references/

scripts/

templates/

SKILL.md106 lines
1
---
2
name: websocket-implementation
3
description: >
4
Implement real-time bidirectional communication with WebSockets including
5
connection management, message routing, and scaling. Use when building
6
real-time features, chat systems, live notifications, or collaborative
7
applications.
8
---
9
10
# WebSocket Implementation
11
12
## Table of Contents
13
14
- [Overview](#overview)
15
- [When to Use](#when-to-use)
16
- [Quick Start](#quick-start)
17
- [Reference Guides](#reference-guides)
18
- [Best Practices](#best-practices)
19
20
## Overview
21
22
Build scalable WebSocket systems for real-time communication with proper connection management, message routing, error handling, and horizontal scaling support.
23
24
## When to Use
25
26
- Building real-time chat and messaging
27
- Implementing live notifications
28
- Creating collaborative editing tools
29
- Broadcasting live data updates
30
- Building real-time dashboards
31
- Streaming events to clients
32
- Live multiplayer games
33
34
## Quick Start
35
36
Minimal working example:
37
38
```javascript
39
const express = require("express");
40
const http = require("http");
41
const socketIo = require("socket.io");
42
const redis = require("redis");
43
44
const app = express();
45
const server = http.createServer(app);
46
const io = socketIo(server, {
47
cors: { origin: "*" },
48
transports: ["websocket", "polling"],
49
reconnection: true,
50
reconnectionDelay: 1000,
51
reconnectionDelayMax: 5000,
52
reconnectionAttempts: 5,
53
});
54
55
// Redis adapter for horizontal scaling
56
const redisClient = redis.createClient();
57
const { createAdapter } = require("@socket.io/redis-adapter");
58
59
io.adapter(createAdapter(redisClient, redisClient.duplicate()));
60
61
// Connection management
62
const connectedUsers = new Map();
63
64
// ... (see reference guides for full implementation)
65
```
66
67
## Reference Guides
68
69
Detailed implementations in the `references/` directory:
70
71
| Guide | Contents |
72
|---|---|
73
| [Node.js WebSocket Server (Socket.IO)](references/nodejs-websocket-server-socketio.md) | Node.js WebSocket Server (Socket.IO) |
74
| [Browser WebSocket Client](references/browser-websocket-client.md) | Browser WebSocket Client |
75
| [Python WebSocket Server (aiohttp)](references/python-websocket-server-aiohttp.md) | Python WebSocket Server (aiohttp) |
76
| [Message Types and Protocols](references/message-types-and-protocols.md) | Message Types and Protocols |
77
| [Scaling with Redis](references/scaling-with-redis.md) | Scaling with Redis |
78
79
## Best Practices
80
81
### ✅ DO
82
83
- Implement proper authentication
84
- Handle reconnection gracefully
85
- Manage rooms/channels effectively
86
- Persist messages appropriately
87
- Monitor active connections
88
- Implement presence features
89
- Use Redis for scaling
90
- Add message acknowledgment
91
- Implement rate limiting
92
- Handle errors properly
93
94
### ❌ DON'T
95
96
- Send unencrypted sensitive data
97
- Keep unlimited message history in memory
98
- Allow arbitrary room/channel creation
99
- Forget to clean up disconnected connections
100
- Send large messages frequently
101
- Ignore network failures
102
- Store passwords in messages
103
- Skip authentication/authorization
104
- Create unbounded growth of connections
105
- Ignore scalability from day one
106

© AJ Geddes · MIT · source · posted by @OpenSourceBuffGuy on promptparty.com

@OpenSourceBuffGuy

I find openly licensed prompts and post them here.

0 followers · 13,329 prompts

More by @OpenSourceBuffGuy

See all
Woman leaps into leaf pile revealing pool prompt image

Woman leaps into leaf pile revealing pool

Generates a one-shot autumn gag where someone announces the first day of fall and leaps into a leaf pile that hides a tiny blue kiddie pool.

video-prompt, comedy, autumn, single-take, wide-shot, golden-hour, vibrant-colors, humorous, timed-beats, lip-sync, natural-light, short-form-video, quick, cinematic, action, transformation

Seaside morning vlog from bedroom to terrace prompt image

Seaside morning vlog from bedroom to terrace

Generates a 15-second vertical seaside vlog of a woman waking up, stepping onto a terrace and speaking to camera, with a beat for every second and written dialogue.

video-prompt, vlog, timed-beats, multi-shot, lip-sync, short-form-video, vertical-format, selfie, ocean, travel, natural-light, golden-hour, character-consistency, handheld, camera-movement, cinematic, photorealistic, woman, hailuo, for-content-creators, long-form, structured-output, bokeh, summer, text-to-video

Giant chocolate bar towering over snowy mountain valley prompt image

Giant chocolate bar towering over snowy mountain valley

Draws a photorealistic chocolate advertisement of a gigantic bar towering over a snowy mountain valley, with tiny photographers and floating chocolate pieces.

image-prompt, product-photography, advertising, surreal, forced-perspective, mountains, winter, landscape, golden-hour, photorealistic, cinematic, vertical-format, luxury, food-photography, packaging-design, negative-prompt, gpt-image, chatgpt, quick, vibrant-colors, dramatic-lighting, wide-shot

Reviews

Loading reviews…

Discussion

Loading comments…