public class WebSocketAdapter extends Object implements WebSocketListener
WebSocketListener
.
Convenient abstract class to base standard WebSocket implementations off of.
Constructor and Description |
---|
WebSocketAdapter() |
Modifier and Type | Method and Description |
---|---|
WebSocketBlockingConnection |
getBlockingConnection() |
WebSocketConnection |
getConnection() |
boolean |
isConnected() |
boolean |
isNotConnected() |
void |
onWebSocketBinary(byte[] payload,
int offset,
int len)
A WebSocket binary frame has been received.
|
void |
onWebSocketClose(int statusCode,
String reason)
A Close Event was received.
|
void |
onWebSocketConnect(WebSocketConnection connection)
A WebSocketConnection has connected successfully and is ready to be used.
|
void |
onWebSocketException(WebSocketException error)
A WebSocket exception has occurred.
|
void |
onWebSocketText(String message)
A WebSocket Text frame was received.
|
public WebSocketBlockingConnection getBlockingConnection()
public WebSocketConnection getConnection()
public boolean isConnected()
public boolean isNotConnected()
public void onWebSocketBinary(byte[] payload, int offset, int len)
WebSocketListener
onWebSocketBinary
in interface WebSocketListener
payload
- the raw payload array receivedoffset
- the offset in the payload array where the data startslen
- the length of bytes in the payloadpublic void onWebSocketClose(int statusCode, String reason)
WebSocketListener
The underlying WebSocketConnection
will be considered closed at this point.
onWebSocketClose
in interface WebSocketListener
statusCode
- the close status code. (See StatusCode
)reason
- the optional reason for the close.public void onWebSocketConnect(WebSocketConnection connection)
WebSocketListener
Note: It is a good idea to track this connection as a field in your object so that you can write messages back.
onWebSocketConnect
in interface WebSocketListener
connection
- the connection to use to send messages on.public void onWebSocketException(WebSocketException error)
WebSocketListener
Usually this occurs from bad / malformed incoming packets. (example: bad UTF8 data, frames that are too big, violations of the spec)
This will result in the WebSocketConnection
being closed by the implementing side.
Note: you will receive no WebSocketListener.onWebSocketClose(int, String)
as this condition results in the API calling
BaseConnection.close(int, String)
for you.
onWebSocketException
in interface WebSocketListener
error
- the error that occurred.public void onWebSocketText(String message)
WebSocketListener
onWebSocketText
in interface WebSocketListener
Copyright © 1995-2012 Mort Bay Consulting. All Rights Reserved.