public interface WebSocket
Instances of this interface are thread-safe. Outbound operations may be
invoked from arbitrary application threads. Inbound events are delivered
to the associated WebSocketListener.
Outbound calls return true when the frame has been accepted for
transmission. They do not indicate that the peer has received or processed
the message. Applications that require acknowledgements must implement them
at the protocol layer.
The close handshake follows RFC 6455. Applications should call
close(int, String) and wait for the WebSocketListener.onClose(int, String)
callback to consider the connection terminated.
| Modifier and Type | Method and Description |
|---|---|
CompletableFuture<Void> |
close(int statusCode,
String reason)
Initiates the WebSocket close handshake.
|
boolean |
isOpen()
Returns
true if the WebSocket is still open and not in the
process of closing. |
boolean |
ping(ByteBuffer data)
Sends a PING control frame with the given payload.
|
boolean |
pong(ByteBuffer data)
Sends a PONG control frame with the given payload.
|
long |
queueSize()
Returns the number of bytes currently queued for outbound transmission.
|
boolean |
sendBinary(ByteBuffer data,
boolean finalFragment)
Sends a binary message fragment.
|
boolean |
sendBinaryBatch(List<ByteBuffer> fragments,
boolean finalFragment)
Sends a batch of binary fragments as a single message.
|
boolean |
sendText(CharSequence data,
boolean finalFragment)
Sends a text message fragment.
|
boolean |
sendTextBatch(List<CharSequence> fragments,
boolean finalFragment)
Sends a batch of text fragments as a single message.
|
boolean isOpen()
true if the WebSocket is still open and not in the
process of closing.boolean ping(ByteBuffer data)
The payload size must not exceed 125 bytes.
data - optional payload buffer; may be null.true if the frame was accepted for sending,
false if the connection is closing or closed.boolean pong(ByteBuffer data)
The payload size must not exceed 125 bytes.
data - optional payload buffer; may be null.true if the frame was accepted for sending,
false if the connection is closing or closed.boolean sendText(CharSequence data, boolean finalFragment)
data - text data to send. Must not be null.finalFragment - true if this is the final fragment of
the message, false if more fragments
will follow.true if the fragment was accepted for sending,
false if the connection is closing or closed.boolean sendBinary(ByteBuffer data, boolean finalFragment)
data - binary data to send. Must not be null.finalFragment - true if this is the final fragment of
the message, false if more fragments
will follow.true if the fragment was accepted for sending,
false if the connection is closing or closed.boolean sendTextBatch(List<CharSequence> fragments, boolean finalFragment)
fragments - ordered list of fragments; must not be null
or empty.finalFragment - true if this batch completes the logical
message, false if subsequent batches
will follow.true if the batch was accepted for sending,
false if the connection is closing or closed.boolean sendBinaryBatch(List<ByteBuffer> fragments, boolean finalFragment)
fragments - ordered list of fragments; must not be null
or empty.finalFragment - true if this batch completes the logical
message, false if subsequent batches
will follow.true if the batch was accepted for sending,
false if the connection is closing or closed.long queueSize()
This value is intended for backpressure and observability. It reflects bytes accepted by the implementation but not fully written to the transport yet.
-1 if unavailableCompletableFuture<Void> close(int statusCode, String reason)
The returned future is completed once the close frame has been queued for sending. It does not wait for the peer's close frame or for the underlying TCP connection to be closed.
statusCode - close status code to send.reason - optional close reason; may be null.Copyright © 1999–2021 The Apache Software Foundation. All rights reserved.