ABNORMAL_CLOSE, END_POINT_GOING_DOWN, INVALID_DATA, MESSAGE_TOO_LARGE, NO_STATUS_CODE, NORMAL_CLOSURE, PROTOCOL_ERROR| Constructor and Description |
|---|
DefaultWebSocket(ProtocolHandler protocolHandler,
WebSocketRequest request,
WebSocketListener... listeners) |
| Modifier and Type | Method and Description |
|---|---|
boolean |
add(WebSocketListener listener)
Adds a
WebSocketListener to be notified of events of interest. |
void |
close()
Closes this
WebSocket. |
void |
close(int code)
Closes this
WebSocket using the specified status code. |
void |
close(int code,
String reason)
Closes this
WebSocket using the specified status code and
reason. |
Collection<WebSocketListener> |
getListeners() |
WebSocketRequest |
getUpgradeRequest()
Returns the upgrade request for this WebSocket.
|
boolean |
isConnected()
Convenience method to determine if this
WebSocket is connected. |
void |
onClose(ClosingFrame frame)
This callback will be invoked when the remote end-point sent a closing
frame.
|
void |
onConnect()
This callback will be invoked when the opening handshake between both
endpoints has been completed.
|
void |
onFragment(boolean last,
byte[] fragment)
This callback will be invoked when a fragmented binary message has
been received.
|
void |
onFragment(boolean last,
String fragment)
This callback will be invoked when a fragmented textual message has
been received.
|
void |
onMessage(byte[] data)
This callback will be invoked when a binary message has been received.
|
void |
onMessage(String text)
This callback will be invoked when a text message has been received.
|
void |
onPing(DataFrame frame)
This callback will be invoked when the remote end-point has sent a ping
frame.
|
void |
onPong(DataFrame frame)
This callback will be invoked when the remote end-point has sent a pong
frame.
|
boolean |
remove(WebSocketListener listener)
Removes the specified
WebSocketListener as a target of event
notification. |
Future<DataFrame> |
send(byte[] data)
Send a binary frame to the remote end-point.
|
Future<DataFrame> |
send(String data)
Send a text frame to the remote end-point.
|
Future<DataFrame> |
sendPing(byte[] data)
Sends a
ping frame with the specified payload (if any). |
Future<DataFrame> |
sendPong(byte[] data)
Sends a
ping frame with the specified payload (if any). |
void |
setClosed() |
Future<DataFrame> |
stream(boolean last,
byte[] bytes,
int off,
int len)
Sends a fragment of a complete message.
|
Future<DataFrame> |
stream(boolean last,
String fragment)
Sends a fragment of a complete message.
|
public DefaultWebSocket(ProtocolHandler protocolHandler, WebSocketRequest request, WebSocketListener... listeners)
public WebSocketRequest getUpgradeRequest()
public Collection<WebSocketListener> getListeners()
public final boolean add(WebSocketListener listener)
WebSocketWebSocketListener to be notified of events of interest.add in interface WebSocketlistener - the WebSocketListener to add.true if the listener was added, otherwise
falseWebSocketListenerpublic final boolean remove(WebSocketListener listener)
WebSocketWebSocketListener as a target of event
notification.remove in interface WebSocketlistener - the WebSocketListener to remote.true if the listener was removed, otherwise
falseWebSocketListenerpublic boolean isConnected()
WebSocket
Convenience method to determine if this WebSocket is connected.
isConnected in interface WebSockettrue if the WebSocket is connected, otherwise
falsepublic void setClosed()
public void onClose(ClosingFrame frame)
WebSocketThis callback will be invoked when the remote end-point sent a closing frame.
public void onConnect()
WebSocketThis callback will be invoked when the opening handshake between both endpoints has been completed.
public void onFragment(boolean last,
byte[] fragment)
WebSocketThis callback will be invoked when a fragmented binary message has been received.
onFragment in interface WebSocketlast - flag indicating whether or not the payload received is the
final fragment of a message.fragment - the binary data received from the remote end-point.public void onFragment(boolean last,
String fragment)
WebSocketThis callback will be invoked when a fragmented textual message has been received.
onFragment in interface WebSocketlast - flag indicating whether or not the payload received is the
final fragment of a message.fragment - the text received from the remote end-point.public void onMessage(byte[] data)
WebSocketThis callback will be invoked when a binary message has been received.
public void onMessage(String text)
WebSocketThis callback will be invoked when a text message has been received.
public void onPing(DataFrame frame)
WebSocketThis callback will be invoked when the remote end-point has sent a ping frame.
public void onPong(DataFrame frame)
WebSocketThis callback will be invoked when the remote end-point has sent a pong frame.
public void close(int code)
WebSocket
Closes this WebSocket using the specified status code.
public void close(int code,
String reason)
WebSocket
Closes this WebSocket using the specified status code and
reason.
public Future<DataFrame> send(byte[] data)
WebSocketSend a binary frame to the remote end-point.
public Future<DataFrame> send(String data)
WebSocketpublic Future<DataFrame> sendPing(byte[] data)
WebSocket
Sends a ping frame with the specified payload (if any).
public Future<DataFrame> sendPong(byte[] data)
WebSocket
Sends a ping frame with the specified payload (if any).
It may seem odd to send a pong frame, however, RFC-6455 states:
"A Pong frame MAY be sent unsolicited. This serves as a unidirectional heartbeat. A response to an unsolicited Pong frame is not expected."
public Future<DataFrame> stream(boolean last, String fragment)
WebSocketSends a fragment of a complete message.
public Future<DataFrame> stream(boolean last, byte[] bytes, int off, int len)
WebSocketSends a fragment of a complete message.
stream in interface WebSocketlast - boolean indicating if this message fragment is the last.bytes - the binary fragment to send.off - the offset within the fragment to send.len - the number of bytes of the fragment to send.Future which could be used to control/check the sending completion state.Copyright © 2012-2013. All Rights Reserved.