public enum WebSocketState extends Enum<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 and Description |
---|
CLOSED
The WebSocket connection is closed.
|
CLOSING
A closing
handshake is being performed.
|
CONNECTING
An opening
handshake is being performed.
|
CREATED
The initial state of a
WebSocket instance. |
OPEN
The WebSocket connection is established (= the opening handshake
has succeeded) and usable.
|
Modifier and Type | Method and Description |
---|---|
static WebSocketState |
valueOf(String name)
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.
|
public static final WebSocketState CREATED
WebSocket
instance.public static final WebSocketState CONNECTING
public static final WebSocketState OPEN
public static final WebSocketState CLOSING
public static final WebSocketState CLOSED
public static WebSocketState[] values()
for (WebSocketState c : WebSocketState.values()) System.out.println(c);
public static WebSocketState valueOf(String name)
name
- the name of the enum constant to be returned.IllegalArgumentException
- if this enum type has no constant with the specified nameNullPointerException
- if the argument is nullCopyright © 2021. All rights reserved.