Websocket implementation

From aj-geddes/useful-ai-prompts · View interactive version

Websocket implementation is an AI agent skill from the GitHub repository aj-geddes/useful-ai-prompts. Implement real-time bidirectional communication with WebSockets including connection management, message routing, and scaling. Use when building real-time features, chat systems, live notifications, or collaborative applications.

How to use this skill

Skill file

WebSocket Implementation

Table of Contents

Overview

Build scalable WebSocket systems for real-time communication with proper connection management, message routing, error handling, and horizontal scaling support.

When to Use

Quick Start

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)

Reference Guides

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 |

Best Practices

✅ DO

❌ DON'T

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.