All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.neovisionaries.ws.client.WebSocketState Maven / Gradle / Ivy

There is a newer version: 2.14
Show newest version
/*
 * Copyright (C) 2015-2016 Neo Visionaries Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.neovisionaries.ws.client;


/**
 * WebSocket state.
 *
 * 

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

* *

* At the beginning of the implementation of {@code connect()} method, * the state is changed to CONNECTING, and then * {@link WebSocketListener#onStateChanged(WebSocket, WebSocketState) * onStateChanged()} method of each registered listener ({@link * WebSocketListener}) is called. *

* *

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

* *

* After the opening handshake succeeded, the state is changed to * OPEN. Listeners' {@code onStateChanged()} method * and {@link WebSocketListener#onConnected(WebSocket, java.util.Map) * onConnected()} method are called in this order. Note that {@code * 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 {@code onStateChanged()} method of * listeners is called. *

* *

* After the client and the server have exchanged close frames, the * state is changed to CLOSED. Listeners' * {@code onStateChanged()} method and {@link * WebSocketListener#onDisconnected(WebSocket, WebSocketFrame, * WebSocketFrame, boolean) onDisconnected()} method is called in * this order. *

*/ public enum WebSocketState { /** * The initial state of a {@link WebSocket} instance. */ CREATED, /** * An opening * handshake is being performed. */ CONNECTING, /** * The WebSocket connection is established (= the opening handshake * has succeeded) and usable. */ OPEN, /** * A closing * handshake is being performed. */ CLOSING, /** * The WebSocket connection is closed. */ CLOSED }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy