Package ej.websocket

Class CloseCodes


  • public final class CloseCodes
    extends Object
    RFC6455 defined a list a status codes (section 7.4.1) and reserved code ranges (section 7.4.2). This class provided these codes and methods to validate that a given number is not a reserved value.

    According to Section 5.5.1, a status code is a "2-byte unsigned integer (in network byte order)". In Java, we will use 'int' (signed 4-byte integer) to store it.

    Note that comments for public constants are taken from the RFC6455.

    See Also:
    ReasonForClosure
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int CLIENT_EXPECTED_EXTENSIONS_FROM_SERVER
      1010 indicates that an endpoint (client) is terminating the connection because it has expected the server to negotiate one or more extension, but the server didn't return them in the response message of the WebSocket handshake.
      static int CONNECTION_CLOSED_ABNORMALLY
      1006 is a reserved value and MUST NOT be set as a status code in a Close control frame by an endpoint.
      static int GOING_AWAY
      1001 indicates that an endpoint is "going away", such as a server going down or a browser having navigated away from a page.
      static int INVALID_INCOMING_DATA_TYPE
      1003 indicates that an endpoint is terminating the connection because it has received a type of data it cannot accept (e.g., an endpoint that understands only text data MAY send this if it receives a binary message).
      static int MESSAGE_TO_BIG
      1009 indicates that an endpoint is terminating the connection because it has received a message that is too big for it to process.
      static int NO_STATUS_PROVIDED
      1005 is a reserved value and MUST NOT be set as a status code in a Close control frame by an endpoint.
      static int NORMAL_CLOSURE
      1000 indicates a normal closure, meaning that the purpose for which the connection was established has been fulfilled.
      static int POLICY_VIOLATION
      1008 indicates that an endpoint is terminating the connection because it has received a message that violates its policy.
      static int PROTOCOL_ERROR
      1002 indicates that an endpoint is terminating the connection due to a protocol error.
      static int RECEIVED_INCONSISTENT_DATA
      1007 indicates that an endpoint is terminating the connection because it has received data within a message that was not consistent with the type of the message (e.g., non-UTF-8 [RFC3629] data within a text message).
      static int RESERVED_1004
      Reserved.
      static int SERVER_CANNOT_FULFILL_REQUEST
      1011 indicates that a server is terminating the connection because it encountered an unexpected condition that prevented it from fulfilling the request.
      static int TLS_HANDSHAKE_FAILED
      1015 is a reserved value and MUST NOT be set as a status code in a Close control frame by an endpoint.
    • Field Detail

      • NORMAL_CLOSURE

        public static final int NORMAL_CLOSURE
        1000 indicates a normal closure, meaning that the purpose for which the connection was established has been fulfilled.
        See Also:
        Constant Field Values
      • GOING_AWAY

        public static final int GOING_AWAY
        1001 indicates that an endpoint is "going away", such as a server going down or a browser having navigated away from a page.
        See Also:
        Constant Field Values
      • PROTOCOL_ERROR

        public static final int PROTOCOL_ERROR
        1002 indicates that an endpoint is terminating the connection due to a protocol error.
        See Also:
        Constant Field Values
      • INVALID_INCOMING_DATA_TYPE

        public static final int INVALID_INCOMING_DATA_TYPE
        1003 indicates that an endpoint is terminating the connection because it has received a type of data it cannot accept (e.g., an endpoint that understands only text data MAY send this if it receives a binary message).
        See Also:
        Constant Field Values
      • RESERVED_1004

        public static final int RESERVED_1004
        Reserved. The specific meaning might be defined in the future.
        See Also:
        Constant Field Values
      • NO_STATUS_PROVIDED

        public static final int NO_STATUS_PROVIDED
        1005 is a reserved value and MUST NOT be set as a status code in a Close control frame by an endpoint. It is designated for use in applications expecting a status code to indicate that no status code was actually present.
        See Also:
        Constant Field Values
      • CONNECTION_CLOSED_ABNORMALLY

        public static final int CONNECTION_CLOSED_ABNORMALLY
        1006 is a reserved value and MUST NOT be set as a status code in a Close control frame by an endpoint. It is designated for use in applications expecting a status code to indicate that the connection was closed abnormally, e.g., without sending or receiving a Close control frame.
        See Also:
        Constant Field Values
      • RECEIVED_INCONSISTENT_DATA

        public static final int RECEIVED_INCONSISTENT_DATA
        1007 indicates that an endpoint is terminating the connection because it has received data within a message that was not consistent with the type of the message (e.g., non-UTF-8 [RFC3629] data within a text message).
        See Also:
        Constant Field Values
      • POLICY_VIOLATION

        public static final int POLICY_VIOLATION
        1008 indicates that an endpoint is terminating the connection because it has received a message that violates its policy. This is a generic status code that can be returned when there is no other more suitable status code (e.g., 1003 or 1009) or if there is a need to hide specific details about the policy.
        See Also:
        Constant Field Values
      • MESSAGE_TO_BIG

        public static final int MESSAGE_TO_BIG
        1009 indicates that an endpoint is terminating the connection because it has received a message that is too big for it to process.
        See Also:
        Constant Field Values
      • CLIENT_EXPECTED_EXTENSIONS_FROM_SERVER

        public static final int CLIENT_EXPECTED_EXTENSIONS_FROM_SERVER
        1010 indicates that an endpoint (client) is terminating the connection because it has expected the server to negotiate one or more extension, but the server didn't return them in the response message of the WebSocket handshake. The list of extensions that are needed SHOULD appear in the /reason/ part of the Close frame. Note that this status code is not used by the server, because it can fail the WebSocket handshake instead.
        See Also:
        Constant Field Values
      • SERVER_CANNOT_FULFILL_REQUEST

        public static final int SERVER_CANNOT_FULFILL_REQUEST
        1011 indicates that a server is terminating the connection because it encountered an unexpected condition that prevented it from fulfilling the request.
        See Also:
        Constant Field Values
      • TLS_HANDSHAKE_FAILED

        public static final int TLS_HANDSHAKE_FAILED
        1015 is a reserved value and MUST NOT be set as a status code in a Close control frame by an endpoint. It is designated for use in applications expecting a status code to indicate that the connection was closed due to a failure to perform a TLS handshake (e.g., the server certificate can't be verified).
        See Also:
        Constant Field Values
    • Method Detail

      • canBeUsedInCloseFrame

        public static boolean canBeUsedInCloseFrame​(int code)
        Tell if can be used in a close control frame. See sections:
        • 7.4.2. Reserved Status Code Range.
        • 7.4.1. Defined Status Codes
        Parameters:
        code - the code to test
        Returns:
        true if 'code' is valid, 'false' otherwise.