HTML and CSS Reference
In-Depth Information
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
Code
Description
When to Use this Code
1000
Normal Close
Send this code when your session has
successfully completed.
1001
Going Away
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.
1002
Protocol Error
Send this code when closing the connection due
to a protocol error.
1003
Unacceptable Data Type
Send this code when your application receives a
message of an unexpected type that it
cannot handle.
1004
Reserved
Do not send this code. According to RFC 6455,
this status code is reserved and may be defined
in the future.
1005
Reserved
Do not send this code. The WebSocket API uses
this code to indicate that no code was received.
1006
Reserved
Do not send this code. The Websocket API uses
this code to indicate that the connection has
closed abnormally.
1007
Invalid Data
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.
1008
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 )
 
Search WWH ::




Custom Search