⚠️
Maintenance. Notice: the site is currently in maintenance mode, so the amount of available material is temporarily limited.
The numbers and APIs you keep looking up — ready states, close codes, frame opcodes and the client/server surface, on one page.
Числа и API, которые постоянно приходится искать — состояния, коды закрытия, опкоды кадров и поверхность клиент/сервер на одной странице.
| Value | Constant | Meaning |
|---|---|---|
0 | CONNECTING | Handshake in progress; send() throws. |
1 | OPEN | Ready; you may send and receive. |
2 | CLOSING | Close handshake started. |
3 | CLOSED | Closed, or the connection failed to open. |
| Значение | Константа | Значение |
|---|---|---|
0 | CONNECTING | Идёт рукопожатие; send() бросает исключение. |
1 | OPEN | Готово; можно отправлять и принимать. |
2 | CLOSING | Начато закрывающее рукопожатие. |
3 | CLOSED | Закрыто или не удалось открыть. |
| Code | Name | When |
|---|---|---|
1000 | Normal Closure | Clean, intentional close. |
1001 | Going Away | Server shutting down or page navigating away. |
1006 | Abnormal Closure | Connection dropped with no close frame (network loss). |
1008 | Policy Violation | Generic “you broke a rule” — e.g. auth/token failure. |
1009 | Message Too Big | Frame exceeded the receiver's limit. |
1011 | Internal Error | Server hit an unexpected condition. |
1012 | Service Restart | Reconnect after a backoff; common during deploys. |
3000–4999 | App-defined | Your own codes (e.g. 4401 for re-login). |
| Код | Имя | Когда |
|---|---|---|
1000 | Normal Closure | Чистое преднамеренное закрытие. |
1001 | Going Away | Сервер выключается или уход со страницы. |
1006 | Abnormal Closure | Разрыв без close-кадра (потеря сети). |
1008 | Policy Violation | Общее «нарушение правила» — напр. ошибка авторизации/токена. |
1009 | Message Too Big | Кадр превысил лимит получателя. |
1011 | Internal Error | Непредвиденная ситуация на сервере. |
1012 | Service Restart | Переподключиться после backoff; типично при выкатке. |
3000–4999 | Прикладные | Ваши коды (напр. 4401 для перелогина). |
| Opcode | Type | Notes |
|---|---|---|
0x0 | Continuation | Continues a fragmented message. |
0x1 | Text | UTF-8 payload — arrives as a string. |
0x2 | Binary | Arrives as Blob or ArrayBuffer. |
0x8 | Close | Control frame; carries a close code. |
0x9 | Ping | Control frame; browsers auto-reply with pong. |
0xA | Pong | Reply to a ping; used for heartbeats. |
| Опкод | Тип | Заметки |
|---|---|---|
0x0 | Continuation | Продолжение фрагментированного сообщения. |
0x1 | Text | UTF-8 — приходит как строка. |
0x2 | Binary | Приходит как Blob или ArrayBuffer. |
0x8 | Close | Управляющий кадр; несёт код закрытия. |
0x9 | Ping | Управляющий кадр; браузеры авто-отвечают pong. |
0xA | Pong | Ответ на ping; используется для heartbeat. |
const ws = new WebSocket(url, protocols?); // properties ws.readyState // 0..3 ws.bufferedAmount // bytes queued, not yet sent ws.protocol // negotiated subprotocol ws.binaryType // "blob" | "arraybuffer" // methods ws.send(data); // string | Blob | ArrayBuffer | TypedArray ws.close(code?, reason?); // events ws.onopen / onmessage / onclose / onerror
import { WebSocketServer } from "ws"; const wss = new WebSocketServer({ port, server?, path? }); wss.on("connection", (ws, req) => { … }); wss.clients // Set of connected sockets ws.send(data, { binary }); ws.ping() / ws.pong(); ws.terminate(); // hard close, no handshake ws.on("message" | "close" | "pong" | "error", fn);
Need the “why” behind these? Each row links to a guide in the tutorials. Нужно «почему» за этими цифрами? Каждая тема разобрана в уроках.