public enum WebSocketState extends Enum<WebSocketState>
WebSocket state.
<p>
The initial state of a WebSocket instance is
<b><code>CREATED</code></b>. 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).
</p>
<p>
At the beginning of the implementation of connect() method,
the state is changed to <b><code>CONNECTING</code></b>, and then
onStateChanged() method of each registered listener (WebSocketListener) is called.
</p>
<p>
After the state is changed to CONNECTING, a WebSocket
<a href="https://tools.ietf.org/html/rfc6455#section-4">opening
handshake</a> 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.
</p>
<p>
After the opening handshake succeeded, the state is changed to
<b><code>OPEN</code></b>. Listeners' onStateChanged() method
and onConnected() method are called in this order. Note that onConnected() method is called by another thread.
</p>
<p>
Upon either sending or receiving a <a href=
"https://tools.ietf.org/html/rfc6455#section-5.5.1">close frame</a>,
a <a href="https://tools.ietf.org/html/rfc6455#section-7">closing
handshake</a> is started. The state is changed to
<b><code>CLOSING</code></b> and onStateChanged() method of
listeners is called.
</p>
<p>
After the client and the server have exchanged close frames, the
state is changed to <b><code>CLOSED</code></b>. Listeners'
onStateChanged() method and onDisconnected() method is called in
this order.
</p>
| Enum Constant and Description |
|---|
CLOSED
The WebSocket connection is closed.
|
CLOSING
A <a href="https://tools.ietf.org/html/rfc6455#section-7">closing
handshake</a> is being performed.
|
CONNECTING
An <a href="https://tools.ietf.org/html/rfc6455#section-4">opening
handshake</a> is being performed.
|
CREATED
The initial state of a
WebSocket instance. |
OPEN
The WebSocket connection is established (= the <a href=
"https://tools.ietf.org/html/rfc6455#section-4">opening handshake</a>
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
The initial state of a WebSocket instance.
public static final WebSocketState CONNECTING
An <a href="https://tools.ietf.org/html/rfc6455#section-4">opening handshake</a> is being performed.
public static final WebSocketState OPEN
The WebSocket connection is established (= the <a href= "https://tools.ietf.org/html/rfc6455#section-4">opening handshake</a> has succeeded) and usable.
public static final WebSocketState CLOSING
A <a href="https://tools.ietf.org/html/rfc6455#section-7">closing handshake</a> is being performed.
public static final WebSocketState CLOSED
The WebSocket connection is 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.