Modifier and Type | Field and Description |
---|---|
protected ProtocolHandler |
protocolHandler |
protected HttpRequestPacket |
request |
ABNORMAL_CLOSE, END_POINT_GOING_DOWN, INVALID_DATA, MESSAGE_TOO_LARGE, NO_STATUS_CODE, NORMAL_CLOSURE, PROTOCOL_ERROR
Constructor and Description |
---|
DefaultWebSocket(ProtocolHandler protocolHandler,
HttpRequestPacket request,
WebSocketListener... listeners) |
DefaultWebSocket(ProtocolHandler protocolHandler,
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() |
HttpRequestPacket |
getUpgradeRequest()
Returns the upgrade request for this WebSocket.
|
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[] 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. |
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). |
void |
setClosed() |
GrizzlyFuture<DataFrame> |
stream(boolean last,
byte[] bytes,
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.
|
protected final ProtocolHandler protocolHandler
protected final HttpRequestPacket request
public DefaultWebSocket(ProtocolHandler protocolHandler, WebSocketListener... listeners)
public DefaultWebSocket(ProtocolHandler protocolHandler, HttpRequestPacket request, WebSocketListener... listeners)
public HttpRequestPacket getUpgradeRequest()
public Collection<WebSocketListener> getListeners()
public final boolean add(WebSocketListener listener)
WebSocket
WebSocketListener
to be notified of events of interest.add
in interface WebSocket
listener
- the WebSocketListener
to add.true
if the listener was added, otherwise
false
WebSocketListener
public final boolean remove(WebSocketListener listener)
WebSocket
WebSocketListener
as a target of event
notification.remove
in interface WebSocket
listener
- the WebSocketListener
to remote.true
if the listener was removed, otherwise
false
WebSocketListener
public boolean isConnected()
WebSocket
Convenience method to determine if this WebSocket
is connected.
isConnected
in interface WebSocket
true
if the WebSocket
is connected, otherwise
false
public void setClosed()
public void onClose(DataFrame frame)
WebSocket
This callback will be invoked when the remote end-point sent a closing frame.
public void onConnect()
WebSocket
This callback will be invoked when the opening handshake between both endpoints has been completed.
public void onFragment(boolean last, byte[] fragment)
WebSocket
This callback will be invoked when a fragmented binary message has been received.
onFragment
in interface WebSocket
last
- 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)
WebSocket
This callback will be invoked when a fragmented textual message has been received.
onFragment
in interface WebSocket
last
- 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)
WebSocket
This callback will be invoked when a binary message has been received.
public void onMessage(String text)
WebSocket
This callback will be invoked when a text message has been received.
public void onPing(DataFrame frame)
WebSocket
This callback will be invoked when the remote end-point has sent a ping frame.
public void onPong(DataFrame frame)
WebSocket
This 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 GrizzlyFuture<DataFrame> send(byte[] data)
WebSocket
Send a binary frame to the remote end-point.
send
in interface WebSocket
GrizzlyFuture
which could be used to control/check the sending completion state.public GrizzlyFuture<DataFrame> send(String data)
WebSocket
Send a text frame to the remote end-point.
send
in interface WebSocket
GrizzlyFuture
which could be used to control/check the sending completion state.public GrizzlyFuture<DataFrame> sendPing(byte[] data)
Sends a ping
frame with the specified payload (if any).
sendPing
in interface WebSocket
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.public 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."
sendPong
in interface WebSocket
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.public GrizzlyFuture<DataFrame> stream(boolean last, String fragment)
WebSocket
Sends a fragment of a complete message.
stream
in interface WebSocket
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.public GrizzlyFuture<DataFrame> stream(boolean last, byte[] bytes, int off, int len)
WebSocket
Sends a fragment of a complete message.
stream
in interface WebSocket
last
- 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.GrizzlyFuture
which could be used to control/check the sending completion state.Copyright © 2013 Oracle Corporation. All Rights Reserved.