|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.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,
WebSocketDraft draft)
Constructs a WebSocketClient instance and sets it to the connect to the specified URI. |
Method Summary | |
---|---|
void |
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. |
WebSocketDraft |
getDraft()
Called to retrieve the Draft of this listener. |
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. |
boolean |
onHandshakeRecieved(WebSocket conn,
java.lang.String handshake,
byte[] reply)
Parses the server's handshake to verify that it's a valid WebSocket handshake. |
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 |
run()
|
void |
send(java.lang.String text)
Sends text to the connected WebSocket server. |
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, WebSocketDraft draft)
serverUri
- The URI of the WebSocket server to connect to.Method Detail |
---|
public java.net.URI getURI()
public WebSocketDraft getDraft()
public void connect()
public void close() throws java.io.IOException
java.io.IOException
- When socket related I/O errors occur.public void send(java.lang.String text) throws java.io.IOException
text
- The String to send to the WebSocket server.
java.io.IOException
- When socket related I/O errors occur.public void run()
run
in interface java.lang.Runnable
public boolean onHandshakeRecieved(WebSocket conn, java.lang.String handshake, byte[] reply) throws java.io.IOException, java.security.NoSuchAlgorithmException
conn
- The WebSocket
instance who's handshake has been recieved.
In the case of WebSocketClient, this.conn == conn.handshake
- The entire UTF-8 decoded handshake from the connection.
java.io.IOException
- When socket related I/O errors occur.
java.security.NoSuchAlgorithmException
public void onMessage(WebSocket conn, java.lang.String message)
conn
- message
- public void onOpen(WebSocket conn)
conn
- public void onClose(WebSocket conn)
conn
- public abstract void onMessage(java.lang.String message)
public abstract void onOpen()
public abstract void onClose()
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |