Enum WebSocketState

java.lang.Object
java.lang.Enum<WebSocketState>
com.neovisionaries.ws.client.WebSocketState
All Implemented Interfaces:
Serializable, Comparable<WebSocketState>

public enum WebSocketState extends Enum<WebSocketState>
WebSocket state.

The initial state of a WebSocket instance is CREATED. WebSocket.connect() method is allowed to be called only when the state is CREATED. If the method is called when the state is not CREATED, a WebSocketException is thrown (its error code is NOT_IN_CREATED_STATE).

At the beginning of the implementation of connect() method, the state is changed to CONNECTING, and then onStateChanged() method of each registered listener (WebSocketListener) is called.

After the state is changed to CONNECTING, a WebSocket opening handshake is performed. If an error occurred during the handshake, the state is changed to CLOSED ( onStateChanged() method of listeners is called) and a WebSocketException is thrown. There are various reasons for handshake failure. If you want to know the reason, get the error code (WebSocketError) by calling getError() method of the exception.

After the opening handshake succeeded, the state is changed to OPEN. Listeners' onStateChanged() method and onConnected() method are called in this order. Note that onConnected() method is called by another thread.

Upon either sending or receiving a close frame, a closing handshake is started. The state is changed to CLOSING and onStateChanged() method of listeners is called.

After the client and the server have exchanged close frames, the state is changed to CLOSED. Listeners' onStateChanged() method and onDisconnected() method is called in this order.

  • Enum Constant Details

  • Constructor Details

    • WebSocketState

      private WebSocketState()
  • Method Details

    • values

      public static WebSocketState[] values()
      Returns an array containing the constants of this enum type, in the order they are declared.
      Returns:
      an array containing the constants of this enum type, in the order they are declared
    • valueOf

      public static WebSocketState valueOf(String name)
      Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum type has no constant with the specified name
      NullPointerException - if the argument is null