Session represents an active link of
communication with a remote WebSocket endpoint.
Session APIs can be used to configure
the various parameters that control the behavior
of the WebSocket communication, such as
setMaxTextMessageSize(long), and to send
WebSocket frames or messages to the other peer.
The passive link of communication that receives
WebSocket events is Listener.
| Modifier and Type | Class and Description |
|---|---|
| public static interface | Session.
The passive link of communication with a remote WebSocket endpoint. |
| Modifier and Type | Method and Description |
|---|---|
| public default void | close()
Implements java. Equivalent to |
| public void | close(int
the status code statusCode, String the (optional) reason reason, Callback callback to notify when the send operation is complete callback)Sends a websocket CLOSE frame, with status code and reason, notifying the given callback when the frame send is completed, either successfully or with a failure. |
| public void | |
| public void | |
| public SocketAddress | |
| public String | Returns: the WebSocket protocol versionReturns the version of the WebSocket protocol currently being used. |
| public SocketAddress | |
| public UpgradeRequest | |
| public UpgradeResponse | |
| public boolean | |
| public boolean | |
| public void | sendBinary(ByteBuffer
the message bytes to send buffer, Callback callback to notify when the send operation is complete callback)Initiates the asynchronous send of a BINARY message, notifying the given callback when the message send is completed, either successfully or with a failure. |
| public void | sendPartialBinary(ByteBuffer
the frame bytes to send buffer, boolean whether this is the last frame of the message last, Callback callback to notify when the send operation is complete callback)Initiates the asynchronous send of a BINARY frame, possibly part of a larger binary message, notifying the given callback when the frame send is completed, either successfully or with a failure. |
| public void | sendPartialText(String
the frame text to send text, boolean whether this is the last frame of the message last, Callback callback to notify when the send operation is complete callback)Initiates the asynchronous send of a TEXT frame, possibly part of a larger binary message, notifying the given callback when the frame send is completed, either successfully or with a failure. |
| public void | sendPing(ByteBuffer
the data to be carried in the PING frame applicationData, Callback callback to notify when the send operation is complete callback)Initiates the asynchronous send of a PING frame, notifying the given callback when the frame send is completed, either successfully or with a failure. |
| public void | sendPong(ByteBuffer
the data to be carried in the PONG frame applicationData, Callback callback to notify when the send operation is complete callback)Initiates the asynchronous send of a PONG frame, notifying the given callback when the frame send is completed, either successfully or with a failure. |
| public void |
| close | back to summary |
|---|---|
| public default void close() Implements java. Equivalent to
| |
| close | back to summary |
|---|---|
| public void close(int statusCode, String reason, Callback callback) Sends a websocket CLOSE frame, with status code and reason, notifying the given callback when the frame send is completed, either successfully or with a failure.
| |
| demand | back to summary |
|---|---|
| public void demand() Explicitly demands for WebSocket events. This method should be called only when the WebSocket endpoint is not
demanding automatically, as defined by In general, invoking this method results in a listener method or an annotated method to be called when the corresponding event is ready to be delivered. For WebSocket endpoints that wants to receive frame events
(for example by overriding For WebSocket endpoints that want to receive whole message
events (for example by overriding Note that even when the WebSocket endpoint is interested in whole messages, calling this method is necessary not only to possibly receive the next whole message, but also to receive control frames (such as PING or CLOSE frames). Failing to call this method after receiving a whole message results in the CLOSE frame event to not be processed, and therefore for the endpoint to not notice when the other peer closed the WebSocket communication.
| |
| disconnect | back to summary |
|---|---|
| public void disconnect() Abruptly closes the WebSocket connection without sending a CLOSE frame.
| |
| getLocalSocketAddress | back to summary |
|---|---|
public SocketAddress getLocalSocketAddress()
| |
| getProtocolVersion | back to summary |
|---|---|
| public String getProtocolVersion() Returns the version of the WebSocket protocol currently being used. This is taken as the value of the
| |
| getRemoteSocketAddress | back to summary |
|---|---|
public SocketAddress getRemoteSocketAddress()
| |
| getUpgradeRequest | back to summary |
|---|---|
public UpgradeRequest getUpgradeRequest()
| |
| getUpgradeResponse | back to summary |
|---|---|
public UpgradeResponse getUpgradeResponse()
| |
| isOpen | back to summary |
|---|---|
public boolean isOpen()
| |
| isSecure | back to summary |
|---|---|
public boolean isSecure()
| |
| sendBinary | back to summary |
|---|---|
| public void sendBinary(ByteBuffer buffer, Callback callback) Initiates the asynchronous send of a BINARY message, notifying the given callback when the message send is completed, either successfully or with a failure.
| |
| sendPartialBinary | back to summary |
|---|---|
| public void sendPartialBinary(ByteBuffer buffer, boolean last, Callback callback) Initiates the asynchronous send of a BINARY frame, possibly part of a larger binary message, notifying the given callback when the frame send is completed, either successfully or with a failure. Non-final frames must be sent with the parameter
| |
| sendPartialText | back to summary |
|---|---|
| public void sendPartialText(String text, boolean last, Callback callback) Initiates the asynchronous send of a TEXT frame, possibly part of a larger binary message, notifying the given callback when the frame send is completed, either successfully or with a failure. Non-final frames must be sent with the parameter | |
| sendPing | back to summary |
|---|---|
| public void sendPing(ByteBuffer applicationData, Callback callback) Initiates the asynchronous send of a PING frame, notifying the given callback when the frame send is completed, either successfully or with a failure.
| |
| sendPong | back to summary |
|---|---|
| public void sendPong(ByteBuffer applicationData, Callback callback) Initiates the asynchronous send of a PONG frame, notifying the given callback when the frame send is completed, either successfully or with a failure.
| |
| sendText | back to summary |
|---|---|
| public void sendText(String text, Callback callback) Initiates the asynchronous send of a TEXT message, notifying the given callback when the message send is completed, either successfully or with a failure. | |
The passive link of communication with a remote WebSocket endpoint.
Applications provide WebSocket endpoints that implement this interface
to receive WebSocket events from the remote peer, and can use
Session for configuration and to send WebSocket frames or messages
to the other peer.
| Modifier and Type | Class and Description |
|---|---|
| public abstract static class | |
| public abstract static class | |
| public static interface | Session.
Tag interface that signals that the WebSocket endpoint is demanding for WebSocket frames automatically. |
| Modifier and Type | Method and Description |
|---|---|
| public default void | onWebSocketBinary(ByteBuffer
the raw payload array received payload, Callback callback)A WebSocket BINARY message has been received. |
| public default void | onWebSocketClose(int
the close statusCode, String status codethe optional reason for the close reason)The WebSocket |
| public default void | onWebSocketError(Throwable
the error that occurred cause)A WebSocket error has occurred during the processing of WebSocket frames. |
| public default void | onWebSocketFrame(Frame
the received frame frame, Callback callback)A WebSocket frame has been received. |
| public default void | onWebSocketOpen(Session
the WebSocket session session)A WebSocket |
| public default void | onWebSocketPartialBinary(ByteBuffer
the BINARY frame payload payload, boolean whether this is the last frame last, Callback the callback to complete when the payload has been processed callback)A WebSocket BINARY (or associated CONTINUATION) frame has been received. |
| public default void | onWebSocketPartialText(String
the text message payload
payload, boolean Note that due to framing, there is a above average chance of any UTF8 sequences being split on the border between two frames will result in either the previous frame, or the next frame having an invalid UTF8 sequence, but the combined frames having a valid UTF8 sequence. The String being provided here will not end in a split UTF8 sequence. Instead this partial sequence will be held over until the next frame is received. whether this is the last frame last)A WebSocket TEXT (or associated CONTINUATION) frame has been received. |
| public default void | |
| public default void | |
| public default void |
| onWebSocketBinary | back to summary |
|---|---|
| public default void onWebSocketBinary(ByteBuffer payload, Callback callback) A WebSocket BINARY message has been received.
| |
| onWebSocketClose | back to summary |
|---|---|
| public default void onWebSocketClose(int statusCode, String reason) The WebSocket
| |
| onWebSocketError | back to summary |
|---|---|
| public default void onWebSocketError(Throwable cause) A WebSocket error has occurred during the processing of WebSocket frames. Usually errors occurs from bad or malformed incoming packets, for example text frames that do not contain UTF-8 bytes, frames that are too big, or other violations of the WebSocket specification. The WebSocket
| |
| onWebSocketFrame | back to summary |
|---|---|
| public default void onWebSocketFrame(Frame frame, Callback callback) A WebSocket frame has been received. The received frames may be control frames such as PING, PONG or CLOSE, or data frames either BINARY or TEXT.
| |
| onWebSocketOpen | back to summary |
|---|---|
| public default void onWebSocketOpen(Session session) A WebSocket Applications can store the given
| |
| onWebSocketPartialBinary | back to summary |
|---|---|
| public default void onWebSocketPartialBinary(ByteBuffer payload, boolean last, Callback callback) A WebSocket BINARY (or associated CONTINUATION) frame has been received. The
| |
| onWebSocketPartialText | back to summary |
|---|---|
| public default void onWebSocketPartialText(String payload, boolean last) A WebSocket TEXT (or associated CONTINUATION) frame has been received.
| |
| onWebSocketPing | back to summary |
|---|---|
| public default void onWebSocketPing(ByteBuffer payload) A WebSocket PING frame has been received.
| |
| onWebSocketPong | back to summary |
|---|---|
| public default void onWebSocketPong(ByteBuffer payload) A WebSocket PONG frame has been received.
| |
| onWebSocketText | back to summary |
|---|---|
| public default void onWebSocketText(String message) A WebSocket TEXT message has been received.
| |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public Session | |
| public boolean | |
| public void | onWebSocketOpen(Session
the WebSocket session session)Overrides default org. A WebSocket |
| session | back to summary |
|---|---|
| private volatile Session session | |
| Abstract | back to summary |
|---|---|
| public Abstract() | |
| getSession | back to summary |
|---|---|
| public Session getSession() | |
| isOpen | back to summary |
|---|---|
| public boolean isOpen() | |
| onWebSocketOpen | back to summary |
|---|---|
| public void onWebSocketOpen(Session session) Overrides default org. Doc from org. A WebSocket Applications can store the given | |
| Access | Constructor and Description |
|---|---|
| public |
| AbstractAutoDemanding | back to summary |
|---|---|
| public AbstractAutoDemanding() | |
Tag interface that signals that the WebSocket endpoint is demanding for WebSocket frames automatically.
WebSocket#autoDemand()