public abstract class WebSocketClient
extends java.lang.Object
| Constructor and Description |
|---|
WebSocketClient(java.net.URI uri)
Initialize all the variables
|
| Modifier and Type | Method and Description |
|---|---|
void |
addHeader(java.lang.String key,
java.lang.String value)
Adds a new header to the set of headers that will be send into the
handshake This header will be added to the set of headers: Host, Upgrade,
Connection, Sec-WebSocket-Key, Sec-WebSocket-Version
|
void |
close()
Closes the WebSocket connection
|
void |
connect()
Starts a new connection to the WebSocket server
|
void |
disableAutomaticReconnection()
Indicates that a connection must not be reopened automatically due to an
IOException
|
void |
enableAutomaticReconnection(long waitTimeBeforeReconnection)
Indicates that a connection must be reopened automatically due to an
IOException.
|
abstract void |
onBinaryReceived(byte[] data)
Called when a binary message has been received
|
abstract void |
onCloseReceived()
Called when a close code has been received
|
abstract void |
onException(java.lang.Exception e)
Called when an exception has occurred
|
abstract void |
onOpen()
Called when the WebSocket handshake has been accepted and the WebSocket
is ready to send and receive data
|
abstract void |
onPingReceived(byte[] data)
Called when a ping message has been received
|
abstract void |
onPongReceived(byte[] data)
Called when a pong message has been received
|
abstract void |
onTextReceived(java.lang.String message)
Called when a text message has been received
|
void |
send(byte[] data)
Sends a binary message If the WebSocket is not connected yet, message
will be send the next time the connection is opened
|
void |
send(java.lang.String message)
Sends a text message If the WebSocket is not connected yet, message will
be send the next time the connection is opened
|
void |
setConnectTimeout(int connectTimeout)
Set the timeout that will be used while the WebSocket is being connected
If timeout expires before connecting, an IOException will be thrown
|
void |
setReadTimeout(int readTimeout)
Sets the timeout for considering and idle connection as dead An idle
connection is a connection that has not received data for a long time If
timeout expires, an IOException will be thrown and you should consider
opening a new WebSocket connection, or delegate this functionality to
this WebSocketClient using the method setAutomaticReconnection(true)
|
public WebSocketClient(java.net.URI uri)
uri - URI of the WebSocket serverpublic abstract void onOpen()
public abstract void onTextReceived(java.lang.String message)
message - The UTF-8 encoded text receivedpublic abstract void onBinaryReceived(byte[] data)
data - The binary message receivedpublic abstract void onPingReceived(byte[] data)
data - Optional datapublic abstract void onPongReceived(byte[] data)
data - Optional datapublic abstract void onException(java.lang.Exception e)
e - The exception that occurredpublic abstract void onCloseReceived()
public void addHeader(java.lang.String key,
java.lang.String value)
key - Name of the new headervalue - Value of the new headerpublic void setConnectTimeout(int connectTimeout)
connectTimeout - Timeout in millisecondspublic void setReadTimeout(int readTimeout)
readTimeout - Read timeout in milliseconds before considering an idle
connection as deadpublic void enableAutomaticReconnection(long waitTimeBeforeReconnection)
waitTimeBeforeReconnection - Wait time in milliseconds before trying to establish a new
WebSocket connection. For performance reasons, you should set
a wait time greater than zeropublic void disableAutomaticReconnection()
public void connect()
public void send(java.lang.String message)
message - Message that will be send to the WebSocket serverpublic void send(byte[] data)
data - Binary data that will be send to the WebSocket serverpublic void close()