Top Description Fields Methods
org.glassfish.grizzly.websockets

public Interface WebSocket

Known Direct Implementers
org.glassfish.grizzly.websockets.SimpleWebSocket
Imports
org.glassfish.grizzly.GrizzlyFuture

General WebSocket unit interface.
Author
Alexey Stashok

Field Summary

Modifier and TypeField and Description
public static final int
ABNORMAL_CLOSE

a reserved value and MUST NOT be set as a status code in a Close control frame by an endpoint.

public static final 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.

public static final int
INVALID_DATA

Indicates that an endpoint is terminating the connection because it has received a type of data it cannot accept (e.g. an endpoint that understands only text data may send this if it receives a binary message.)

public static final int
MESSAGE_TOO_LARGE

indicates that an endpoint is terminating the connection because it has received a message that is too large.

public static final int
NO_STATUS_CODE

a reserved value and MUST NOT be set as a status code in a Close control frame by an endpoint.

public static final int
NORMAL_CLOSURE

Indicates a normal closure, meaning whatever purpose the connection was established for has been fulfilled.

public static final int
PROTOCOL_ERROR

Indicates that an endpoint is terminating the connection due to a protocol error.

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true if the listener was added, otherwise false
add
(WebSocketListener
the WebSocketListener to add.
listener
)

Adds a WebSocketListener to be notified of events of interest.

public void
broadcast(final Iterable<? extends WebSocket> recipients, String data)

Broadcasts the data to the remote end-point set.

public void
broadcast(final Iterable<? extends WebSocket> recipients, byte[] data)

Broadcasts the data to the remote end-point set.

public void
broadcastFragment(final Iterable<? extends WebSocket> recipients, String data, boolean last)

Broadcasts the data fragment to the remote end-point set.

public void
broadcastFragment(final Iterable<? extends WebSocket> recipients, byte[] data, boolean last)

Broadcasts the data fragment to the remote end-point set.

public void
close()

Closes this WebSocket.

public void
close(int
the closing status code.
code
)

Closes this WebSocket using the specified status code.

public void
close(int
the closing status code.
code
,
String
the reason, if any.
reason
)

Closes this WebSocket using the specified status code and reason.

public boolean

Returns:

true if the WebSocket is connected, otherwise false
isConnected
()

Convenience method to determine if this WebSocket is connected.

public void
onClose(DataFrame
the close frame from the remote end-point.
frame
)

This callback will be invoked when the remote end-point sent a closing frame.

public void
onConnect()

This callback will be invoked when the opening handshake between both endpoints has been completed.

public void
onFragment(boolean
flag indicating whether or not the payload received is the final fragment of a message.
last
,
String
the text received from the remote end-point.
payload
)

This callback will be invoked when a fragmented textual message has been received.

public void
onFragment(boolean
flag indicating whether or not the payload received is the final fragment of a message.
last
,
byte[]
the binary data received from the remote end-point.
payload
)

This callback will be invoked when a fragmented binary message has been received.

public void
onMessage(String
the text received from the remote end-point.
text
)

This callback will be invoked when a text message has been received.

public void
onMessage(byte[]
the binary data received from the remote end-point.
data
)

This callback will be invoked when a binary message has been received.

public void
onPing(DataFrame
the ping frame from the remote end-point.
frame
)

This callback will be invoked when the remote end-point has sent a ping frame.

public void
onPong(DataFrame
the pong frame from the remote end-point.
frame
)

This callback will be invoked when the remote end-point has sent a pong frame.

public boolean

Returns:

true if the listener was removed, otherwise false
remove
(WebSocketListener
the WebSocketListener to remote.
listener
)

Removes the specified WebSocketListener as a target of event notification.

public GrizzlyFuture<DataFrame>

Returns:

GrizzlyFuture which could be used to control/check the sending completion state.
send
(String data)

Send a text frame to the remote end-point.

public GrizzlyFuture<DataFrame>

Returns:

GrizzlyFuture which could be used to control/check the sending completion state.
send
(byte[] data)

Send a binary frame to the remote end-point.

public GrizzlyFuture<DataFrame>

Returns:

GrizzlyFuture which could be used to control/check the sending completion state.
sendPing
(byte[]
optional payload. Note that payload length is restricted to 125 bytes or less.
data
)

Sends a ping frame with the specified payload (if any).

public GrizzlyFuture<DataFrame>

Returns:

GrizzlyFuture which could be used to control/check the sending completion state.
sendPong
(byte[]
optional payload. Note that payload length is restricted to 125 bytes or less.
data
)

Sends a ping frame with the specified payload (if any).

public GrizzlyFuture<DataFrame>

Returns:

GrizzlyFuture which could be used to control/check the sending completion state.
stream
(boolean
boolean indicating if this message fragment is the last.
last
,
String
the textual fragment to send.
fragment
)

Sends a fragment of a complete message.

public GrizzlyFuture<DataFrame>

Returns:

GrizzlyFuture which could be used to control/check the sending completion state.
stream
(boolean
boolean indicating if this message fragment is the last.
last
,
byte[]
the binary fragment to send.
fragment
,
int
the offset within the fragment to send.
off
,
int
the number of bytes of the fragment to send.
len
)

Sends a fragment of a complete message.

Field Detail

ABNORMAL_CLOSEback to summary
public static final int ABNORMAL_CLOSE

a reserved value and MUST NOT be set as a status code in a Close control frame by an endpoint. It is designated for use in applications expecting a status code to indicate that the connection was closed abnormally, e.g. without sending or receiving a Close control frame.

END_POINT_GOING_DOWNback to summary
public static final 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.

INVALID_DATAback to summary
public static final int INVALID_DATA

Indicates that an endpoint is terminating the connection because it has received a type of data it cannot accept (e.g. an endpoint that understands only text data may send this if it receives a binary message.)

MESSAGE_TOO_LARGEback to summary
public static final int MESSAGE_TOO_LARGE

indicates that an endpoint is terminating the connection because it has received a message that is too large.

NO_STATUS_CODEback to summary
public static final int NO_STATUS_CODE

a reserved value and MUST NOT be set as a status code in a Close control frame by an endpoint. It is designated for use in applications expecting a status code to indicate that no status code was actually present.

NORMAL_CLOSUREback to summary
public static final int NORMAL_CLOSURE

Indicates a normal closure, meaning whatever purpose the connection was established for has been fulfilled.

PROTOCOL_ERRORback to summary
public static final int PROTOCOL_ERROR

Indicates that an endpoint is terminating the connection due to a protocol error.

Method Detail

addback to summary
public boolean add(WebSocketListener listener)

Adds a WebSocketListener to be notified of events of interest.

Parameters
listener:WebSocketListener

the WebSocketListener to add.

Returns:boolean

true if the listener was added, otherwise false

See Also
WebSocketListener
broadcastback to summary
public void broadcast(final Iterable<? extends WebSocket> recipients, String data)

Broadcasts the data to the remote end-point set.

broadcastback to summary
public void broadcast(final Iterable<? extends WebSocket> recipients, byte[] data)

Broadcasts the data to the remote end-point set.

broadcastFragmentback to summary
public void broadcastFragment(final Iterable<? extends WebSocket> recipients, String data, boolean last)

Broadcasts the data fragment to the remote end-point set.

broadcastFragmentback to summary
public void broadcastFragment(final Iterable<? extends WebSocket> recipients, byte[] data, boolean last)

Broadcasts the data fragment to the remote end-point set.

closeback to summary
public void close()

Closes this WebSocket.

closeback to summary
public void close(int code)

Closes this WebSocket using the specified status code.

Parameters
code:int

the closing status code.

closeback to summary
public void close(int code, String reason)

Closes this WebSocket using the specified status code and reason.

Parameters
code:int

the closing status code.

reason:String

the reason, if any.

isConnectedback to summary
public boolean isConnected()

Convenience method to determine if this WebSocket is connected.

Returns:boolean

true if the WebSocket is connected, otherwise false

onCloseback to summary
public void onClose(DataFrame frame)

This callback will be invoked when the remote end-point sent a closing frame.

Parameters
frame:DataFrame

the close frame from the remote end-point.

See Also
DataFrame
onConnectback to summary
public void onConnect()

This callback will be invoked when the opening handshake between both endpoints has been completed.

onFragmentback to summary
public void onFragment(boolean last, String payload)

This callback will be invoked when a fragmented textual message has been received.

Parameters
last:boolean

flag indicating whether or not the payload received is the final fragment of a message.

payload:String

the text received from the remote end-point.

onFragmentback to summary
public void onFragment(boolean last, byte[] payload)

This callback will be invoked when a fragmented binary message has been received.

Parameters
last:boolean

flag indicating whether or not the payload received is the final fragment of a message.

payload:byte[]

the binary data received from the remote end-point.

onMessageback to summary
public void onMessage(String text)

This callback will be invoked when a text message has been received.

Parameters
text:String

the text received from the remote end-point.

onMessageback to summary
public void onMessage(byte[] data)

This callback will be invoked when a binary message has been received.

Parameters
data:byte[]

the binary data received from the remote end-point.

onPingback to summary
public void onPing(DataFrame frame)

This callback will be invoked when the remote end-point has sent a ping frame.

Parameters
frame:DataFrame

the ping frame from the remote end-point.

See Also
DataFrame
onPongback to summary
public void onPong(DataFrame frame)

This callback will be invoked when the remote end-point has sent a pong frame.

Parameters
frame:DataFrame

the pong frame from the remote end-point.

See Also
DataFrame
removeback to summary
public boolean remove(WebSocketListener listener)

Removes the specified WebSocketListener as a target of event notification.

Parameters
listener:WebSocketListener

the WebSocketListener to remote.

Returns:boolean

true if the listener was removed, otherwise false

See Also
WebSocketListener
sendback to summary
public GrizzlyFuture<DataFrame> send(String data)

Send a text frame to the remote end-point.

Returns:GrizzlyFuture<DataFrame>

GrizzlyFuture which could be used to control/check the sending completion state.

sendback to summary
public GrizzlyFuture<DataFrame> send(byte[] data)

Send a binary frame to the remote end-point.

Returns:GrizzlyFuture<DataFrame>

GrizzlyFuture which could be used to control/check the sending completion state.

sendPingback to summary
public GrizzlyFuture<DataFrame> sendPing(byte[] data)

Sends a ping frame with the specified payload (if any).

Parameters
data:byte[]

optional payload. Note that payload length is restricted to 125 bytes or less.

Returns:GrizzlyFuture<DataFrame>

GrizzlyFuture which could be used to control/check the sending completion state.

Since
2.1.9
sendPongback to summary
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."

Parameters
data:byte[]

optional payload. Note that payload length is restricted to 125 bytes or less.

Returns:GrizzlyFuture<DataFrame>

GrizzlyFuture which could be used to control/check the sending completion state.

Since
2.1.9
streamback to summary
public GrizzlyFuture<DataFrame> stream(boolean last, String fragment)

Sends a fragment of a complete message.

Parameters
last:boolean

boolean indicating if this message fragment is the last.

fragment:String

the textual fragment to send.

Returns:GrizzlyFuture<DataFrame>

GrizzlyFuture which could be used to control/check the sending completion state.

streamback to summary
public GrizzlyFuture<DataFrame> stream(boolean last, byte[] fragment, int off, int len)

Sends a fragment of a complete message.

Parameters
last:boolean

boolean indicating if this message fragment is the last.

fragment:byte[]

the binary fragment to send.

off:int

the offset within the fragment to send.

len:int

the number of bytes of the fragment to send.

Returns:GrizzlyFuture<DataFrame>

GrizzlyFuture which could be used to control/check the sending completion state.