Writing WebSocket Server Code With LLMs in November 2026: Authenticate the Upgrade, Check the Origin, and Plan for Dropped Connections
Ask an LLM for "a WebSocket server for live notifications" and you will get something that works on your laptop in about thirty lines. It accepts a connection, broadcasts messages, and logs "client connected." Then it goes to production, and the problems show up: anyone can connect without logging in, a malicious page on another site can open a socket using your users' cookies, connections silently die behind a load balancer, one slow client eats memory, and every deploy disconnects everyone with no plan for reconnecting. None of these are exotic. They are the normal shape of long-lived connections, and generated code tends to skip them because the happy-path demo does not need them. This guide covers what to ask for, what to check in the output, and how to test it before real users rely on it. The examples use Node.js and the widely used ws library, but the same checklist applies to Python, Go, or any other stack. A WebSocket is a line that stays open in b...