|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.java_websocket.WebSocketAdapter
org.java_websocket.client.WebSocketClient
public abstract class WebSocketClient
The WebSocketClient is an abstract class that expects a valid "ws://" URI to connect to. When connected, an instance recieves important events related to the life of the connection. A subclass must implement onOpen, onClose, and onMessage to be useful. An instance can send messages to it's connected server via the send method.
| Nested Class Summary | |
|---|---|
class |
WebSocketClient.DefaultClientProxyChannel
|
static interface |
WebSocketClient.WebSocketClientFactory
|
| Field Summary | |
|---|---|
protected URI |
uri
The URI this channel is supposed to connect to. |
| Constructor Summary | |
|---|---|
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)
|
|
| Method Summary | |
|---|---|
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)
|
| Methods inherited from class org.java_websocket.WebSocketAdapter |
|---|
getFlashPolicy, onWebsocketHandshakeReceivedAsClient, onWebsocketHandshakeReceivedAsServer, onWebsocketHandshakeSentAsClient, onWebsocketMessageFragment, onWebsocketPing, onWebsocketPong |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected URI uri
| Constructor Detail |
|---|
public WebSocketClient(URI serverURI)
public WebSocketClient(URI serverUri,
Draft draft)
public WebSocketClient(URI serverUri,
Draft draft,
Map<String,String> headers,
int connecttimeout)
| Method Detail |
|---|
public URI getURI()
public Draft getDraft()
public void connect()
public boolean connectBlocking()
throws InterruptedException
InterruptedExceptionpublic void close()
public void closeBlocking()
throws InterruptedException
InterruptedException
public void send(String text)
throws NotYetConnectedException
text - The String to send to the WebSocket server.
NotYetConnectedException
public void send(byte[] data)
throws NotYetConnectedException
data - The Byte-Array of data to send to the WebSocket server.
NotYetConnectedExceptionpublic void run()
run in interface Runnablepublic WebSocket.READYSTATE getReadyState()
public final void onWebsocketMessage(WebSocket conn,
String message)
onWebsocketMessage in interface WebSocketListenerconn - message -
public final void onWebsocketMessage(WebSocket conn,
ByteBuffer blob)
WebSocketListener
onWebsocketMessage 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)
WebSocketListener
onWriteDemand in interface WebSocketListener
public void onWebsocketCloseInitiated(WebSocket conn,
int code,
String reason)
WebSocketListener
onWebsocketCloseInitiated in interface WebSocketListener
public void onWebsocketClosing(WebSocket conn,
int code,
String reason,
boolean remote)
WebSocketListener
onWebsocketClosing in interface WebSocketListener
public 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)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||