public interface WebSocket
Modifier and Type | Field and Description |
---|---|
static int |
ABNORMAL_CLOSE
a reserved value and MUST NOT be set as a status code in a Close control frame by an endpoint.
|
static int |
END_POINT_GOING_DOWN
Indicates that an endpoint is "going away", such as a server going down, or a browser having navigated away from
a page.
|
static int |
INVALID_DATA
Indicates that an endpoint is terminating the connection because it has received a type of data it cannot accept
(e.g.
|
static int |
MESSAGE_TOO_LARGE
indicates that an endpoint is terminating the connection because it has received a message that is too large.
|
static int |
NO_STATUS_CODE
a reserved value and MUST NOT be set as a status code in a Close control frame by an endpoint.
|
static int |
NORMAL_CLOSURE
Indicates a normal closure, meaning whatever purpose the connection was established for has been fulfilled.
|
static int |
PROTOCOL_ERROR
Indicates that an endpoint is terminating the connection due to a protocol error.
|
Modifier and Type | Method and Description |
---|---|
boolean |
add(WebSocketListener listener)
Adds a
WebSocketListener to be notified of events of interest. |
void |
broadcast(Iterable<? extends WebSocket> recipients,
byte[] data)
Broadcasts the data to the remote end-point set.
|
void |
broadcast(Iterable<? extends WebSocket> recipients,
String data)
Broadcasts the data to the remote end-point set.
|
void |
broadcastFragment(Iterable<? extends WebSocket> recipients,
byte[] data,
boolean last)
Broadcasts the data fragment to the remote end-point set.
|
void |
broadcastFragment(Iterable<? extends WebSocket> recipients,
String data,
boolean last)
Broadcasts the data fragment to the remote end-point set.
|
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. |
boolean |
isConnected()
Convenience method to determine if this
WebSocket is connected. |
void |
onClose(DataFrame 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[] payload)
This callback will be invoked when a fragmented binary message has
been received.
|
void |
onFragment(boolean last,
String payload)
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. |
GrizzlyFuture<DataFrame> |
send(byte[] data)
Send a binary frame to the remote end-point.
|
GrizzlyFuture<DataFrame> |
send(String data)
Send a text frame to the remote end-point.
|
GrizzlyFuture<DataFrame> |
sendPing(byte[] data)
Sends a
ping frame with the specified payload (if any). |
GrizzlyFuture<DataFrame> |
sendPong(byte[] data)
Sends a
ping frame with the specified payload (if any). |
GrizzlyFuture<DataFrame> |
stream(boolean last,
byte[] fragment,
int off,
int len)
Sends a fragment of a complete message.
|
GrizzlyFuture<DataFrame> |
stream(boolean last,
String fragment)
Sends a fragment of a complete message.
|
static final int NORMAL_CLOSURE
static final int END_POINT_GOING_DOWN
static final int PROTOCOL_ERROR
static final int INVALID_DATA
static final int MESSAGE_TOO_LARGE
static final int NO_STATUS_CODE
static final int ABNORMAL_CLOSE
GrizzlyFuture<DataFrame> send(String data)
Send a text frame to the remote end-point.
GrizzlyFuture
which could be used to control/check the sending completion state.GrizzlyFuture<DataFrame> send(byte[] data)
Send a binary frame to the remote end-point.
GrizzlyFuture
which could be used to control/check the sending completion state.void broadcast(Iterable<? extends WebSocket> recipients, String data)
Broadcasts the data to the remote end-point set.
recipients
- data
- void broadcast(Iterable<? extends WebSocket> recipients, byte[] data)
Broadcasts the data to the remote end-point set.
recipients
- data
- void broadcastFragment(Iterable<? extends WebSocket> recipients, String data, boolean last)
Broadcasts the data fragment to the remote end-point set.
recipients
- data
- void broadcastFragment(Iterable<? extends WebSocket> recipients, byte[] data, boolean last)
Broadcasts the data fragment to the remote end-point set.
recipients
- data
- GrizzlyFuture<DataFrame> sendPing(byte[] data)
ping
frame with the specified payload (if any).
data
- optional payload. Note that payload length is restricted
to 125 bytes or less.GrizzlyFuture
which could be used to control/check the sending completion state.GrizzlyFuture<DataFrame> sendPong(byte[] data)
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."
data
- optional payload. Note that payload length is restricted
to 125 bytes or less.GrizzlyFuture
which could be used to control/check the sending completion state.GrizzlyFuture<DataFrame> stream(boolean last, String fragment)
Sends a fragment of a complete message.
last
- boolean indicating if this message fragment is the last.fragment
- the textual fragment to send.GrizzlyFuture
which could be used to control/check the sending completion state.GrizzlyFuture<DataFrame> stream(boolean last, byte[] fragment, int off, int len)
Sends a fragment of a complete message.
last
- boolean indicating if this message fragment is the last.fragment
- the binary fragment to send.off
- the offset within the fragment to send.len
- the number of bytes of the fragment to send.GrizzlyFuture
which could be used to control/check the sending completion state.void close()
Closes this WebSocket
.
void close(int code)
Closes this WebSocket
using the specified status code.
code
- the closing status code.void close(int code, String reason)
Closes this WebSocket
using the specified status code and
reason.
code
- the closing status code.reason
- the reason, if any.boolean isConnected()
Convenience method to determine if this WebSocket
is connected.
true
if the WebSocket
is connected, otherwise
false
void onConnect()
This callback will be invoked when the opening handshake between both endpoints has been completed.
void onMessage(String text)
This callback will be invoked when a text message has been received.
text
- the text received from the remote end-point.void onMessage(byte[] data)
This callback will be invoked when a binary message has been received.
data
- the binary data received from the remote end-point.void onFragment(boolean last, String payload)
This callback will be invoked when a fragmented textual message has been received.
last
- flag indicating whether or not the payload received is the
final fragment of a message.payload
- the text received from the remote end-point.void onFragment(boolean last, byte[] payload)
This callback will be invoked when a fragmented binary message has been received.
last
- flag indicating whether or not the payload received is the
final fragment of a message.payload
- the binary data received from the remote end-point.void onClose(DataFrame frame)
This callback will be invoked when the remote end-point sent a closing frame.
frame
- the close frame from the remote end-point.DataFrame
void onPing(DataFrame frame)
This callback will be invoked when the remote end-point has sent a ping frame.
frame
- the ping frame from the remote end-point.DataFrame
void onPong(DataFrame frame)
This callback will be invoked when the remote end-point has sent a pong frame.
frame
- the pong frame from the remote end-point.DataFrame
boolean add(WebSocketListener listener)
WebSocketListener
to be notified of events of interest.listener
- the WebSocketListener
to add.true
if the listener was added, otherwise
false
WebSocketListener
boolean remove(WebSocketListener listener)
WebSocketListener
as a target of event
notification.listener
- the WebSocketListener
to remote.true
if the listener was removed, otherwise
false
WebSocketListener
Copyright © 2014 Oracle Corporation. All rights reserved.