public abstract class WebSocketClient extends WebSocketAdapter implements Runnable
| Modifier and Type | Class and Description |
|---|---|
class |
WebSocketClient.DefaultClientProxyChannel |
static interface |
WebSocketClient.WebSocketClientFactory |
| Modifier and Type | Field and Description |
|---|---|
protected URI |
uri
The URI this channel is supposed to connect to.
|
| Constructor and Description |
|---|
WebSocketClient(URI serverURI) |
WebSocketClient(URI serverUri,
Draft draft)
Constructs a WebSocketClient instance and sets it to the connect to the
specified URI.
|
WebSocketClient(URI serverUri,
Draft draft,
Map<String,String> headers,
int connecttimeout) |
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
void |
closeBlocking() |
void |
connect()
Starts a background thread that attempts and maintains a WebSocket
connection to the URI specified in the constructor or via setURI.
|
boolean |
connectBlocking()
Same as connect but blocks until the websocket connected or failed to do so.
Returns whether it succeeded or not. |
ByteChannel |
createProxyChannel(ByteChannel towrap) |
WebSocket |
getConnection() |
Draft |
getDraft()
Returns the protocol version this channel uses.
|
InetSocketAddress |
getLocalSocketAddress(WebSocket conn) |
WebSocket.READYSTATE |
getReadyState()
This represents the state of the connection.
|
InetSocketAddress |
getRemoteSocketAddress(WebSocket conn) |
URI |
getURI()
Gets the URI that this WebSocketClient is connected to.
|
WebSocketFactory |
getWebSocketFactory() |
abstract void |
onClose(int code,
String reason,
boolean remote) |
void |
onCloseInitiated(int code,
String reason) |
void |
onClosing(int code,
String reason,
boolean remote) |
abstract void |
onError(Exception ex) |
void |
onMessage(ByteBuffer bytes) |
abstract void |
onMessage(String message) |
abstract void |
onOpen(ServerHandshake handshakedata) |
void |
onWebsocketClose(WebSocket conn,
int code,
String reason,
boolean remote)
Calls subclass' implementation of onClose.
|
void |
onWebsocketCloseInitiated(WebSocket conn,
int code,
String reason)
send when this peer sends a close handshake
|
void |
onWebsocketClosing(WebSocket conn,
int code,
String reason,
boolean remote)
called as soon as no further frames are accepted
|
void |
onWebsocketError(WebSocket conn,
Exception ex)
Calls subclass' implementation of onIOError.
|
void |
onWebsocketMessage(WebSocket conn,
ByteBuffer blob)
Called when an entire binary frame has been received.
|
void |
onWebsocketMessage(WebSocket conn,
String message)
Calls subclass' implementation of onMessage.
|
void |
onWebsocketOpen(WebSocket conn,
Handshakedata handshake)
Calls subclass' implementation of onOpen.
|
void |
onWriteDemand(WebSocket conn)
This method is used to inform the selector thread that there is data queued to be written to the socket.
|
void |
run() |
void |
send(byte[] data)
Sends data to the connected WebSocket server.
|
void |
send(String text)
Sends text to the connected WebSocket server.
|
void |
setProxy(InetSocketAddress proxyaddress) |
void |
setWebSocketFactory(WebSocketClient.WebSocketClientFactory wsf) |
getFlashPolicy, onWebsocketHandshakeReceivedAsClient, onWebsocketHandshakeReceivedAsServer, onWebsocketHandshakeSentAsClient, onWebsocketMessageFragment, onWebsocketPing, onWebsocketPongprotected URI uri
public WebSocketClient(URI serverURI)
public WebSocketClient(URI serverUri, Draft draft)
public URI getURI()
public Draft getDraft()
public void connect()
public boolean connectBlocking()
throws InterruptedException
InterruptedExceptionpublic void close()
public void closeBlocking()
throws InterruptedException
InterruptedExceptionpublic void send(String text) throws NotYetConnectedException
text - The String to send to the WebSocket server.NotYetConnectedExceptionpublic void send(byte[] data)
throws NotYetConnectedException
data - The Byte-Array of data to send to the WebSocket server.NotYetConnectedExceptionpublic WebSocket.READYSTATE getReadyState()
public final void onWebsocketMessage(WebSocket conn, String message)
onWebsocketMessage in interface WebSocketListenerconn - message - public final void onWebsocketMessage(WebSocket conn, ByteBuffer blob)
WebSocketListeneronWebsocketMessage in interface WebSocketListenerconn - The WebSocket instance this event is occurring on.blob - The binary message that was received.public final void onWebsocketOpen(WebSocket conn, Handshakedata handshake)
onWebsocketOpen in interface WebSocketListenerconn - public final void onWebsocketClose(WebSocket conn, int code, String reason, boolean remote)
onWebsocketClose in interface WebSocketListenerconn - public final void onWebsocketError(WebSocket conn, Exception ex)
onWebsocketError in interface WebSocketListenerconn - ex - The exception that occurred. public final void onWriteDemand(WebSocket conn)
WebSocketListeneronWriteDemand in interface WebSocketListenerpublic void onWebsocketCloseInitiated(WebSocket conn, int code, String reason)
WebSocketListeneronWebsocketCloseInitiated in interface WebSocketListenerpublic void onWebsocketClosing(WebSocket conn, int code, String reason, boolean remote)
WebSocketListeneronWebsocketClosing in interface WebSocketListenerpublic void onCloseInitiated(int code,
String reason)
public void onClosing(int code,
String reason,
boolean remote)
public WebSocket getConnection()
public final void setWebSocketFactory(WebSocketClient.WebSocketClientFactory wsf)
public final WebSocketFactory getWebSocketFactory()
public InetSocketAddress getLocalSocketAddress(WebSocket conn)
getLocalSocketAddress in interface WebSocketListenerpublic InetSocketAddress getRemoteSocketAddress(WebSocket conn)
getRemoteSocketAddress in interface WebSocketListenerpublic abstract void onOpen(ServerHandshake handshakedata)
public abstract void onMessage(String message)
public abstract void onClose(int code,
String reason,
boolean remote)
public abstract void onError(Exception ex)
public void onMessage(ByteBuffer bytes)
public ByteChannel createProxyChannel(ByteChannel towrap)
public void setProxy(InetSocketAddress proxyaddress)
Copyright © 2013. All Rights Reserved.