WebSocket 状态码
A protocol providing full-duplex communication channels over a single TCP connection. Close codes indicate why a connection was terminated.
查看规范 →关于 WebSocket
WebSocket (RFC 6455, 2011) enables persistent, full-duplex communication between a client and server over a single TCP connection. Unlike HTTP's request-response pattern, WebSocket allows both sides to send messages independently at any time — ideal for real-time applications like chat, live dashboards, and multiplayer games. A WebSocket connection begins as an HTTP upgrade handshake (101 Switching Protocols), after which the protocol switches to a binary framing layer. When either side closes the connection, it sends a close frame containing a 2-byte status code: 1000 (Normal Closure), 1001 (Going Away), 1006 (Abnormal Closure — no close frame received), 1008 (Policy Violation), and others. Private-use codes (4000-4999) are available for application-specific semantics. Understanding close codes helps diagnose connection drops, implement reconnection logic, and audit WebSocket traffic.
默认端口:80 · Wikipedia
1000-1015 WebSocket Close Codes
IANA-registered WebSocket close status codes (RFC 6455).
The connection has been closed cleanly, meaning the purpose for which it was established has been fulfilled. Both endpoints agree …
An endpoint is going away, such as a server shutting down or a browser navigating away from the page. The …
An endpoint is terminating the connection because it received data that violates the WebSocket protocol specification.
An endpoint received a type of data it cannot accept. For example, a text-only endpoint received a binary message, or …
A reserved value that indicates no status code was present in the Close frame. This code must not be set …
A reserved value indicating the connection was closed abnormally without a Close frame being sent. This code must not be …
An endpoint received a message with payload data that is inconsistent with the message type. For example, a text message …
An endpoint is terminating the connection because it received a message that violates its policy. This is a generic code …
An endpoint is terminating the connection because it received a message that is too large for it to process.
The client is terminating the connection because the server did not negotiate one or more expected extensions in the handshake …
The server is terminating the connection because it encountered an unexpected condition that prevented it from fulfilling the request.
The server is terminating the connection because it is restarting. The client should reconnect after a brief delay.
The server is terminating the connection due to a temporary condition, such as being overloaded. The client should reconnect after …
The server acting as a gateway or proxy received an invalid response from an upstream server it accessed while attempting …
A reserved value indicating the connection was closed because the TLS handshake failed. This code must not be set by …
WebSocket 指南
Why CORS errors happen and how to fix them — from missing headers to preflight request failures.
Debugging WebSocket DisconnectionsHow to diagnose WebSocket disconnections using close codes, heartbeat analysis, proxy timeouts, and browser DevTools.
WebSocket Close Codes: Why Your Connection DroppedUnderstanding WebSocket close status codes — from normal closure (1000) to protocol errors (1002) and abnormal disconnects (1006).
WebSocket Authentication PatternsHow to authenticate WebSocket connections: token-in-query-string, first-message auth, cookie-based auth, and ticket-based patterns compared.
WebSocket vs Server-Sent Events: Choosing the Right ProtocolHead-to-head comparison of WebSocket and SSE — bidirectional vs unidirectional, browser support, reconnection, and when each protocol shines.
WebRTC Signaling with SIP and WebSocketHow WebRTC peers exchange session descriptions using signaling servers — SIP integration, WebSocket-based signaling, STUN/TURN servers, and ICE candidate negotiation.