public class BaseWebSocketClient extends Object implements WebSocketClient
WebSocket implementation based on
http://weberknecht.googlecode.com by Roderick Baier. This uses thread model
for handling WebSocket connection which is defined by the WebSocket
protocol specification. http://www.whatwg.org/specs/web-socket-protocol/
http://www.w3.org/TR/websockets/| Modifier and Type | Field and Description |
|---|---|
static String |
DATA_CLOSE_CLIENT |
static String |
DATA_CLOSE_ERROR |
static String |
DATA_CLOSE_SERVER |
static String |
DATA_CLOSE_SHUTDOWN |
static String |
EVENT_CLOSE |
static String |
EVENT_OPEN |
protected WebSocketStatus |
mStatus
represents the WebSocket status
|
| Constructor and Description |
|---|
BaseWebSocketClient()
Base constructor
|
BaseWebSocketClient(ReliabilityOptions aReliabilityOptions)
Constructor including reliability options
|
| Modifier and Type | Method and Description |
|---|---|
void |
addListener(WebSocketClientListener aListener)
Adds the client listener to the lists of listener which are interested in
receiving the jWebSocket connection and data events.
|
void |
addSubProtocol(WebSocketSubProtocol aSubProt)
Adds subprotocol to the list of supported protocols which are negotiated
during handshake with web socket server.
|
void |
close()
Close the jWebSocket connection.
|
Socket |
getConnectionSocket() |
WebSocketStatus |
getConnectionStatus() |
Headers |
getHeaders() |
List<WebSocketClientListener> |
getListeners()
Returns the list of listeners registered.
|
WebSocketEncoding |
getNegotiatedEncoding()
If subprotocol was negotiated, then this method returns sub protocol
format (json, csv, binary, custom)
|
String |
getNegotiatedSubProtocol()
If subprotocol was negotiated, then this method returns sub protocol
name.
|
Object |
getParam(String aKey) |
Object |
getParam(String aKey,
Object aDefault) |
ReliabilityOptions |
getReliabilityOptions() |
WebSocketStatus |
getStatus()
Method to return if the status of the jWebSocketClient
|
boolean |
isConnected()
Method to check if the jWebSocketClient is still connected to the
jWebSocketServer
|
void |
notifyClosed(WebSocketClientEvent aEvent)
Notifies the jWebSocket client implementation about the
connection being closed
|
void |
notifyOpened(WebSocketClientEvent aEvent)
Notifies the jWebSocket client implementation about the
connection being opened to the jWebSocket server via WebSocket
|
void |
notifyPacket(WebSocketClientEvent aEvent,
WebSocketPacket aPacket)
Notifies the jWebSocket client implementation about the packet
being received from the WebSocket client.
|
void |
notifyReconnecting(WebSocketClientEvent aEvent)
Notifies the jWebSocket client implementation about the
connection being re-established
|
void |
open(int aVersion,
String aURI) |
void |
open(int aVersion,
String aURI,
String aSubProtocols) |
void |
open(String aURI)
Opens the jWebSocket connection
|
void |
removeListener(WebSocketClientListener aListener)
Remove the listener from the list of listeners, once the listener is
removed it won't be notified of any jWebSocket events.
|
void |
send(byte[] aData)
Send the given byte data to the server
|
void |
send(String aData,
String aEncoding)
Sends the data to the jWebSocket server, data has to be UTF-8 encoded.
|
void |
send(WebSocketPacket aDataPacket)
Sends the websocket data packet to the WebSocket client
|
void |
setParam(String aKey,
Object aValue) |
void |
setReliabilityOptions(ReliabilityOptions mReliabilityOptions) |
void |
setStatus(WebSocketStatus aStatus) |
void |
setVersion(int aVersion)
Web socket protocol draft.
|
protected volatile WebSocketStatus mStatus
public static String EVENT_OPEN
public static String EVENT_CLOSE
public static String DATA_CLOSE_ERROR
public static String DATA_CLOSE_CLIENT
public static String DATA_CLOSE_SERVER
public static String DATA_CLOSE_SHUTDOWN
public BaseWebSocketClient()
public BaseWebSocketClient(ReliabilityOptions aReliabilityOptions)
public void setStatus(WebSocketStatus aStatus) throws Exception
Exceptionpublic void open(String aURI) throws WebSocketException
open in interface WebSocketClientaURI - WebSocketException - if therre's anpublic void open(int aVersion,
String aURI)
aVersion - aURI - WebSocketExceptionpublic void open(int aVersion,
String aURI,
String aSubProtocols)
aVersion - aURI - aSubProtocols - WebSocketExceptionpublic void send(byte[] aData)
throws WebSocketException
WebSocketClientsend in interface WebSocketClientaData - the byte dataWebSocketException - if exception occurs while sending the datapublic void send(String aData, String aEncoding) throws WebSocketException
send in interface WebSocketClientaData - the data to sendaEncoding - the encoding typeWebSocketException - if there's any exception while sending the
datapublic void send(WebSocketPacket aDataPacket) throws WebSocketException
send in interface WebSocketClientaDataPacket - WebSocketException - if there's any exception while sendingpublic void close()
WebSocketClientclose in interface WebSocketClientpublic boolean isConnected()
isConnected in interface WebSocketClienttrue if there's a persistent connection false
otherwisepublic WebSocketStatus getStatus()
WebSocketClientgetStatus in interface WebSocketClientpublic WebSocketStatus getConnectionStatus()
public Socket getConnectionSocket()
public void addListener(WebSocketClientListener aListener)
addListener in interface WebSocketClientaListener - the event listener objectpublic void removeListener(WebSocketClientListener aListener)
removeListener in interface WebSocketClientaListener - the listener object to removepublic List<WebSocketClientListener> getListeners()
getListeners in interface WebSocketClientpublic void notifyOpened(WebSocketClientEvent aEvent)
notifyOpened in interface WebSocketClientaEvent - the websocket client event objectpublic void notifyPacket(WebSocketClientEvent aEvent, WebSocketPacket aPacket)
notifyPacket in interface WebSocketClientaEvent - the websocket client event objectaPacket - the data packet receivedpublic void notifyReconnecting(WebSocketClientEvent aEvent)
notifyReconnecting in interface WebSocketClientaEvent - the websocket client event objectpublic ReliabilityOptions getReliabilityOptions()
public void setReliabilityOptions(ReliabilityOptions mReliabilityOptions)
mReliabilityOptions - the mReliabilityOptions to setpublic Headers getHeaders()
public void notifyClosed(WebSocketClientEvent aEvent)
notifyClosed in interface WebSocketClientaEvent - the websocket client event objectpublic void addSubProtocol(WebSocketSubProtocol aSubProt)
WebSocketClientaddSubProtocol in interface WebSocketClientaSubProt - sub protocolpublic String getNegotiatedSubProtocol()
WebSocketClientgetNegotiatedSubProtocol in interface WebSocketClientpublic WebSocketEncoding getNegotiatedEncoding()
WebSocketClientgetNegotiatedEncoding in interface WebSocketClientpublic void setVersion(int aVersion)
WebSocketClientsetVersion in interface WebSocketClientaVersion - which draft to use for web socket protocol communicationCopyright © 2013. All Rights Reserved.