HTML and CSS Reference
When a WebSocket closes, the endpoint that is terminating the connection can send
a numerical code and a reason string to indicate why it is choosing to close the socket.
The code and reason are encoded in the payload of a frame with the close opcode (8). The
code is represented as an unsigned 16-bit integer. The reason is a short UTF-8 encoded
string. RFC 6455 defines several specific closing codes. Codes 1000-1015 are specified for
use in the WebSocket connection layer. These codes indicate that something has failed in
the network or in the protocol. Table 3-4 lists the codes in this range, their descriptions,
and scenarios in which each code might be applicable.
Table 3-4. Defined WebSocket Closed Codes
When to Use this Code
Send this code when your session has
Send this code when closing the connection
because the application is going away and there
is no expectation that a follow-up connection
will be attempted. The server may be shutting
down or the client application may be closing.
Send this code when closing the connection due
to a protocol error.
Unacceptable Data Type
Send this code when your application receives a
message of an unexpected type that it
Do not send this code. According to RFC 6455,
this status code is reserved and may be defined
in the future.
Do not send this code. The WebSocket API uses
this code to indicate that no code was received.
Do not send this code. The Websocket API uses
this code to indicate that the connection has
Send this code after receiving a message for which
the formatting does not match the message type.
If a text message ever contains malformed UTF-8
data, the connection should close with this code.
Message Violates Policy
Send this code when your application terminates
the connection for a reason not covered by another
code or when you do not wish to disclose the
reason a message cannot be handled.
( continued )