|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectnet.tootallnate.websocket.WebSocketAdapter
net.tootallnate.websocket.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.
| Constructor Summary | |
|---|---|
WebSocketClient(java.net.URI serverURI)
|
|
WebSocketClient(java.net.URI serverUri,
Draft draft)
Constructs a WebSocketClient instance and sets it to the connect to the specified URI. |
|
| Method Summary | |
|---|---|
java.lang.Thread |
close()
Calls close on the underlying SocketChannel, which in turn closes the socket connection, and ends the client socket thread. |
void |
connect()
Starts a background thread that attempts and maintains a WebSocket connection to the URI specified in the constructor or via setURI. |
Draft |
getDraft()
|
java.net.URI |
getURI()
Gets the URI that this WebSocketClient is connected to. |
abstract void |
onClose()
|
void |
onClose(WebSocket conn)
Calls subclass' implementation of onClose. |
abstract void |
onError(java.lang.Exception ex)
|
void |
onError(WebSocket conn,
java.io.IOException ex)
Calls subclass' implementation of onIOError. |
abstract void |
onMessage(java.lang.String message)
|
void |
onMessage(WebSocket conn,
java.lang.String message)
Calls subclass' implementation of onMessage. |
abstract void |
onOpen()
|
void |
onOpen(WebSocket conn)
Calls subclass' implementation of onOpen. |
void |
onWriteDemand(WebSocket conn)
|
void |
run()
|
void |
send(java.lang.String text)
Sends text to the connected WebSocket server. |
| Methods inherited from class net.tootallnate.websocket.WebSocketAdapter |
|---|
getFlashPolicy, onError, onHandshakeRecievedAsClient, onHandshakeRecievedAsServer, onMessage, onPing, onPong |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public WebSocketClient(java.net.URI serverURI)
public WebSocketClient(java.net.URI serverUri,
Draft draft)
| Method Detail |
|---|
public java.net.URI getURI()
public Draft getDraft()
public void connect()
public java.lang.Thread close()
public void send(java.lang.String text)
throws java.nio.channels.NotYetConnectedException,
java.lang.InterruptedException
text - The String to send to the WebSocket server.
java.nio.channels.NotYetConnectedException
java.lang.InterruptedExceptionpublic void run()
run in interface java.lang.Runnable
public void onMessage(WebSocket conn,
java.lang.String message)
onMessage in class WebSocketAdapterconn - message - public void onOpen(WebSocket conn)
onOpen in class WebSocketAdapterconn - public void onClose(WebSocket conn)
onClose in class WebSocketAdapterconn -
public void onError(WebSocket conn,
java.io.IOException ex)
conn - public void onWriteDemand(WebSocket conn)
public abstract void onMessage(java.lang.String message)
public abstract void onOpen()
public abstract void onClose()
public abstract void onError(java.lang.Exception ex)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||