Skip to content
cccskills
FreePublished on GitHub

building-websocket-server

Build a WebSocket server for applications that need live, two-way messages. The workflow covers connection authentication, room subscriptions, message delivery, heartbeat checks for stale connections, and Redis pub/sub for sharing broadcasts across server instances.

OriginalShow the original description

Build scalable WebSocket servers for real-time bidirectional communication. Use when enabling real-time bidirectional communication. Trigger with phrases like "build WebSocket server", "add real-time API", or "implement WebSocket".

jeremylongshore/tons-of-skills-marketplace2,884 stars(GitHub 2,884 + cccskills 0)
Works withRedis

Run score Not tested

See how to install

Good for

  • Adding live messaging to an application
  • Building chat rooms or channels
  • Pushing live dashboard updates
  • Relaying collaborative editing changes

Files included (4)

  • SKILL.md5.1 KB
  • references/errors.md1.0 KB
  • references/examples.md8.2 KB
  • references/implementation.md1.5 KB

SKILL.md (original)

Review the instructions the agent will receive before you install.

Building WebSocket Server

Overview

Build scalable WebSocket servers for real-time bidirectional communication using the ws library, Socket.IO, or native framework WebSocket support. Handle connection lifecycle management, room/channel subscriptions, message broadcasting, heartbeat keepalive, and horizontal scaling with Redis pub/sub adapters.

Prerequisites

  • Node.js 18+ with ws or socket.io, or Python 3.10+ with websockets or FastAPI WebSocket, or Go with gorilla/websocket
  • Redis for horizontal scaling with pub/sub adapter (Socket.IO Redis adapter, or manual pub/sub)
  • Load balancer configured for WebSocket upgrade (sticky sessions or proper Upgrade header forwarding)
  • JWT or session-based authentication for connection handshake
  • Monitoring for active connection counts and message throughput

Instructions

  1. Examine existing HTTP server configuration using Read and Grep to determine the framework and identify where WebSocket upgrade handling integrates.
  2. Create a WebSocket server instance attached to the existing HTTP server, configuring the upgrade path (e.g., /ws, /socket.io) and allowed origins.
  3. Implement connection authentication by validating JWT tokens or session cookies during the WebSocket handshake upgrade event, rejecting unauthorized connections before protocol switch.
  4. Build a connection registry that tracks active clients with metadata (user ID, subscribed channels, connection time) for targeted message delivery.
  5. Define a message protocol using JSON envelopes with type, channel, payload, and correlationId fields for structured bidirectional communication.
  6. Implement room/channel subscription logic allowing clients to join and leave named channels with server-side membership tracking.
  7. Add heartbeat ping/pong mechanism with configurable interval (default 30s) and timeout detection to clean up stale connections.
  8. Configure Redis pub/sub adapter for horizontal scaling so messages broadcast from any server instance reach all connected clients across the cluster.
  9. Write connection lifecycle tests covering connect, authenticate, subscribe, message exchange, reconnect, and graceful disconnect scenarios.

See references/implementation.md for the full implementation guide.

Output

  • ${CLAUDE_SKILL_DIR}/src/ws/server.js - WebSocket server setup and upgrade handling
  • ${CLAUDE_SKILL_DIR}/src/ws/handlers/ - Per-message-type handler functions
  • ${CLAUDE_SKILL_DIR}/src/ws/rooms.js - Room/channel subscription management
  • ${CLAUDE_SKILL_DIR}/src/ws/registry.js - Active connection tracking registry
  • ${CLAUDE_SKILL_DIR}/src/ws/heartbeat.js - Ping/pong keepalive logic
  • ${CLAUDE_SKILL_DIR}/src/ws/adapters/redis.js - Redis pub/sub adapter for scaling
  • ${CLAUDE_SKILL_DIR}/tests/ws/ - WebSocket connection and messaging tests

Error Handling

ErrorCauseSolution
401 during upgradeJWT token missing or expired in handshake query/headersReject upgrade with HTTP 401 before WebSocket protocol switch completes
1008 Policy ViolationClient sends malformed message or violates protocolSend close frame with code 1008 and human-readable reason; log violation
1006 Abnormal ClosureNetwork interruption without close handshakeDetect via heartbeat timeout; clean up connection registry; notify room members
Memory leakConnection registry grows unbounded from stale entriesImplement heartbeat-based cleanup sweep every 60s; enforce max connections per server
Message stormSingle client flooding messages beyond acceptable rateApply per-connection message rate limiting; disconnect abusive clients with 1008

Refer to references/errors.md for comprehensive error patterns.

Examples

Chat application: Multi-room chat server where clients join named rooms, receive member presence updates, and see real-time message delivery with typing indicators via separate message types.

Live dashboard: Server pushes metric updates to subscribed dashboard clients every second, with initial state snapshot on connection and incremental deltas thereafter.

Collaborative editing: Operational transformation relay server that receives edit operations from clients, transforms against concurrent operations, and broadcasts resolved changes to all document subscribers.

See references/examples.md for additional examples.

Resources

Reviews

No reviews yet. Tell others what you thought.

Comments

No login needed. Share how it worked for you, ask a question, or note where it did not run.

No comments yet. Be the first to write one.

Comments are published right away. Do not include personal information such as email addresses or phone numbers. Up to 2 URLs.

0 / 1,000 characters

This form is protected by reCAPTCHA, and the Google Privacy Policy and Terms of Service apply.

More skills from this repository

Add a synthetic-data CI gate for customer-owned Abridge integration code. Test consent handling, note-review handoffs, redaction, and rollback behavior with mocked vendor boundaries, without connecting CI to a live Abridge or EHR tenant.

  • Adding regression checks to an Abridge integration repository
  • Testing consent and note-release handling
  • Checking logs for sensitive data exposure
jeremylongshore/tons-of-skills-marketplace2.9KUpdated Oct 29, 2026

Triage Abridge recording, note review, Epic handoff, and access problems using observed symptoms and approved guidance. Identify the affected workflow stage, organize a minimal timeline, and prepare a redacted escalation record for the responsible team.

  • Separate recording problems from upload failures
  • Investigate note creation delays and editor issues
  • Identify the responsible team for Epic handoff failures
jeremylongshore/tons-of-skills-marketplace2.9KUpdated Oct 29, 2026

Map and review an Abridge clinical documentation workflow from consent and recording through draft review, evidence checks, edits, and final disposition. Keep clinician approval explicit, identify failure exits, and separate verified facts from tenant-specific details and pending approvals.

  • Map a clinical note workflow for a care setting
  • Check where consent and patient identity are verified
  • Review draft notes against linked evidence before sign-off
jeremylongshore/tons-of-skills-marketplace2.9KUpdated Oct 29, 2026

Audit how clinician-reviewed Abridge note sections map into Epic templates and downstream workflows. Use approved test records to document destinations, exceptions, evidence, rollback steps, and a go or no-go decision for a specific environment.

  • Checking Abridge note section mappings to Epic templates
  • Auditing a department’s approved documentation handoff
  • Preparing test evidence and a go or no-go decision
jeremylongshore/tons-of-skills-marketplace2.9KUpdated Oct 29, 2026

Review Abridge adoption and workflow value using local usage records, clinician feedback, and verified contract costs. Build an evidence based decision table covering adoption, quality, support burden, and options to expand, hold, or improve the rollout.

  • Reviewing adoption after an Abridge rollout
  • Preparing evidence for a renewal decision
  • Comparing workflow outcomes across care settings
jeremylongshore/tons-of-skills-marketplace2.9KUpdated Oct 29, 2026

Prepare a bounded support bundle for an Abridge issue using allowlisted operational details such as versions, coarse timestamps, and correlation references. Exclude recordings, transcripts, patient identifiers, credentials, and unrestricted logs, then document redactions and review details.

  • Preparing reviewed evidence for an Abridge support case
  • Documenting redactions and excluded data
  • Collecting approved operational details for an incident
jeremylongshore/tons-of-skills-marketplace2.9KUpdated Oct 29, 2026

See all skills by jeremylongshore

Report a problem with this skill