Enum WebSocketState
- All Implemented Interfaces:
Serializable
,Comparable<WebSocketState>
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 Summary
Enum ConstantsEnum ConstantDescriptionThe WebSocket connection is closed.A closing handshake is being performed.An opening handshake is being performed.The initial state of aWebSocket
instance.The WebSocket connection is established (= the opening handshake has succeeded) and usable. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic WebSocketState
Returns the enum constant of this type with the specified name.static WebSocketState[]
values()
Returns an array containing the constants of this enum type, in the order they are declared.
-
Enum Constant Details
-
CREATED
The initial state of aWebSocket
instance. -
CONNECTING
An opening handshake is being performed. -
OPEN
The WebSocket connection is established (= the opening handshake has succeeded) and usable. -
CLOSING
A closing handshake is being performed. -
CLOSED
The WebSocket connection is closed.
-
-
Constructor Details
-
WebSocketState
private WebSocketState()
-
-
Method Details
-
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
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 nameNullPointerException
- if the argument is null
-