Skip to content
Back to skills

Websocket

ASecurity

Implement a WebSocket server or client with proper handshake, heartbeats, and reconnection

  • 3 stars
  • 0 votes
  • 0 copies
  • 2 views
  • Added September 3, 2026
ai-agentsrustgo

Works with

  • cursor
  • cli

Security analysis

A100/100

Scanned September 3, 2026

npx -y skills add black141312/ada --skill websocket --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Websocket?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Websocket
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/black141312-websocket/badge)](https://www.skillsdirectory.com/skills/black141312-websocket)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: websocket
description: Implement a WebSocket server or client with proper handshake, heartbeats, and reconnection
category: networking
---

# WebSocket

Use for low-latency, bidirectional, long-lived connections (live feeds, chat, collaborative cursors). If the client only ever reads, prefer SSE; if it's request/response, prefer HTTP.

1. Establish the connection: server upgrades the HTTP request (`Upgrade: websocket`), validating `Origin` and authenticating during the handshake (token in query/subprotocol, not after).
2. Define a message protocol — pick JSON or binary, give every message a `type`, and version it so you can evolve the schema.
3. Add ping/pong heartbeats on a timer; close connections that miss N pongs so dead peers and half-open NAT connections get reaped.
4. On the client, implement reconnect with exponential backoff + jitter and resubscribe/replay state after reconnecting.
5. Apply backpressure: bound the send queue per connection and drop or disconnect slow consumers instead of buffering unbounded.
6. Handle clean shutdown — send a close frame with a status code, drain in-flight messages, and remove the connection from any registries.

## Rules
- Always validate `Origin` (and auth) at handshake time; an open upgrade endpoint is a CSRF/abuse vector.
- Never trust message size — cap frame/message length and reject oversized payloads to avoid memory blowups.
- A WebSocket is not reliable delivery: design for dropped connections, duplicate messages on reconnect, and out-of-order resends.
- Use `wss://` in production; plain `ws://` breaks under TLS-terminating proxies and leaks tokens.
- Don't do heavy work in the read loop — hand messages to workers so one slow handler can't stall the socket.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.