Session#getBasicRemote() or
Session#getAsyncRemote(). Objects of this kind include numerous ways to send web socket messages. There are
two kinds of RemoteEndpoint objects: RemoteEndpoint.Basic for synchronous sending of websocket messages, and
RemoteEndpoint.Async for sending messages asynchronously.
There is no guarantee of the successful delivery of a web socket message to the peer, but if the action of sending a message causes an error known to the container, the API throws it. RemoteEndpoints include a variety of ways to send messages: by whole message, in parts, and in various data formats including websocket pings and pongs.
Implementations may or may not support batching of messages. More detail of the expected semantics of implementations
that do support batching are laid out in RemoteEndpoint#setBatchingAllowed(boolean).
Note
Implementations may choose their own schemes for sending large messages in smaller parts. These schemes may or may not bear a relationship to the underlying websocket dataframes in which the message is ultimately sent on the wire.
If the underlying connection is closed and methods on the RemoteEndpoint are attempted to be called, they will result in an error being generated. For the methods that send messages, this will be an IOException, for the methods that alter configuration of the endpoint, this will be runtime IllegalArgumentExceptions.
| Modifier and Type | Class and Description |
|---|---|
| public static interface | RemoteEndpoint.Async
This representation of the peer of a web socket conversation has the ability to send messages asynchronously. |
| public static interface | RemoteEndpoint.Basic
This representation of the peer of a web socket conversation has the ability to send messages synchronously. |
| Modifier and Type | Method and Description |
|---|---|
| public void | |
| public boolean | Returns: true if the implementation is allowed to batch outgoing messages before sending, otherwise
falseReturn whether the implementation is allowed to batch outgoing messages before sending. |
| public void | sendPing(ByteBuffer
the data to be carried in the ping request. applicationData)Send a Ping message containing the given application data to the remote endpoint. |
| public void | sendPong(ByteBuffer
the application data to be carried in the pong response. applicationData)Allows the developer to send an unsolicited Pong message containing the given application data in order to serve as a unidirectional heartbeat for the session. |
| public void | setBatchingAllowed(boolean
whether the implementation is allowed to batch messages. allowed)Indicate to the implementation that it is allowed to batch outgoing messages before sending. |
| flushBatch | back to summary |
|---|---|
| public void flushBatch() throws IOException This method is only used when batching is allowed for this RemoteEndpint. Calling this method forces the implementation to send any unsent messages it has been batching.
| |
| getBatchingAllowed | back to summary |
|---|---|
| public boolean getBatchingAllowed() Return whether the implementation is allowed to batch outgoing messages before sending. The default mode for
RemoteEndpoints is false. The value may be changed by calling
| |
| sendPing | back to summary |
|---|---|
| public void sendPing(ByteBuffer applicationData) throws IOException, IllegalArgumentException Send a Ping message containing the given application data to the remote endpoint. The corresponding Pong message may be picked up using the MessageHandler.Pong handler. It is not safe for other threads to use the ByteBuffer until the sending of this message is complete. If the sending of the message completes successfully, the buffer's limit will be unchanged and the buffer's position will be equal to the limit. If the sending of the message does not complete successfully, the state of the buffer is undefined.
| |
| sendPong | back to summary |
|---|---|
| public void sendPong(ByteBuffer applicationData) throws IOException, IllegalArgumentException Allows the developer to send an unsolicited Pong message containing the given application data in order to serve as a unidirectional heartbeat for the session. It is not safe for other threads to use the ByteBuffer until the sending of this message is complete. If the sending of the message completes successfully, the buffer's limit will be unchanged and the buffer's position will be equal to the limit. If the sending of the message does not complete successfully, the state of the buffer is undefined.
| |
| setBatchingAllowed | back to summary |
|---|---|
| public void setBatchingAllowed(boolean allowed) throws IOException Indicate to the implementation that it is allowed to batch outgoing messages before sending. Not all implementations support batching of outgoing messages. The default mode for RemoteEndpoints is false. If the developer has indicated that batching of outgoing messages is permitted, then the developer must call flushBatch() in order to be sure that all the messages passed into the send methods of this RemoteEndpoint are sent. When batching is allowed, the implementations send operations are considered to have completed if the message has been written to the local batch, in the case when there is still room in the batch for the message, and are considered to have completed if the batch has been send to the peer and the remainder written to the new batch, in the case when writing the message causes the batch to need to be sent. The blocking and asynchronous send methods use this notion of completion in order to complete blocking calls, notify SendHandlers and complete Futures respectively. When batching is allowed, if the developer has called send methods on this RemoteEndpoint without calling flushBatch(), then the implementation may not have sent all the messages the developer has asked to be sent. If the parameter value is false and the implementation has a batch of unsent messages, then the implementation must immediately send the batch of unsent messages.
| |
| Modifier and Type | Method and Description |
|---|---|
| public long | Returns: the timeout time in milliseconds.Return the number of milliseconds the implementation will timeout attempting to send a websocket message. |
| public Future | Returns: the Future object representing the send operation.the data being sent. data)Initiates the asynchronous transmission of a binary message. |
| public void | sendBinary(ByteBuffer
the data being sent, must not be data, SendHandler null.the handler that will be notified of progress, must not be handler)null.Initiates the asynchronous transmission of a binary message. |
| public Future | Returns: the Future object representing the send operation.the object being sent. data)Initiates the asynchronous transmission of a custom developer object. |
| public void | sendObject(Object
the object being sent. data, SendHandler the handler that will be notified of progress, must not be handler)null.Initiates the asynchronous transmission of a custom developer object. |
| public void | sendText(String
the text being sent. text, SendHandler the handler which will be notified of progress. handler)Initiates the asynchronous transmission of a text message. |
| public Future | |
| public void | setSendTimeout(long
The number of milliseconds this RemoteEndpoint will wait before timing out an incomplete
asynchronous message send. timeoutmillis)Sets the number of milliseconds the implementation will timeout attempting to send a websocket message. |
| getSendTimeout | back to summary |
|---|---|
| public long getSendTimeout() Return the number of milliseconds the implementation will timeout attempting to send a websocket message. A zero or negative value indicates the implementation will not timeout attempting to send a websocket message asynchronously. This value overrides the default value assigned in the WebSocketContainer.
| |
| sendBinary | back to summary |
|---|---|
| public Future Initiates the asynchronous transmission of a binary message. This method returns before the message is
transmitted. Developers use the returned Future object to track progress of the transmission. The Future's
get() method returns It is not safe for other threads to use the ByteBuffer until the sending of this message is complete. If the sending of the message completes successfully, the buffer's limit will be unchanged and the buffer's position will be equal to the limit. If the sending of the message does not complete successfully, the state of the buffer is undefined.
| |
| sendBinary | back to summary |
|---|---|
| public void sendBinary(ByteBuffer data, SendHandler handler) Initiates the asynchronous transmission of a binary message. This method returns before the message is transmitted. Developers provide a callback to be notified when the message has been transmitted. Errors in transmission are given to the developer in the SendResult object. It is not safe for other threads to use the ByteBuffer until the sending of this message is complete. If the sending of the message completes successfully, the buffer's limit will be unchanged and the buffer's position will be equal to the limit. If the sending of the message does not complete successfully, the state of the buffer is undefined.
| |
| sendObject | back to summary |
|---|---|
| public Future Initiates the asynchronous transmission of a custom developer object. The developer will have provided an
encoder for this object type in the endpoint configuration. Containers will by default be able to encode java
primitive types and their object equivalents, otherwise the developer must have provided an encoder for the
object type in the endpoint configuration. A developer-provided encoder for a Java primitive type and its
object equivalent overrides the container default encoder. Progress may be tracked using the Future object.
The Future's get() methods return
| |
| sendObject | back to summary |
|---|---|
| public void sendObject(Object data, SendHandler handler) Initiates the asynchronous transmission of a custom developer object. Containers will by default be able to encode java primitive types and their object equivalents, otherwise the developer must have provided an encoder for the object type in the endpoint configuration. A developer-provided encoder for a Java primitive type and its object equivalent overrides the container default encoder. Developers are notified when transmission is complete through the supplied callback object.
| |
| sendText | back to summary |
|---|---|
| public void sendText(String text, SendHandler handler) Initiates the asynchronous transmission of a text message. This method returns before the message is transmitted. Developers provide a callback to be notified when the message has been transmitted. Errors in transmission are given to the developer in the SendResult object.
| |
| sendText | back to summary |
|---|---|
| public Future Initiates the asynchronous transmission of a text message. This method returns before the message is
transmitted. Developers use the returned Future object to track progress of the transmission. The Future's
get() method returns
| |
| setSendTimeout | back to summary |
|---|---|
| public void setSendTimeout(long timeoutmillis) Sets the number of milliseconds the implementation will timeout attempting to send a websocket message. A zero or negative value indicates the implementation will not timeout attempting to send a websocket message asynchronously. This value overrides the default value assigned in the WebSocketContainer.
| |
getSendStream and
getSendWriter which present traditional blocking I/O streams to
write messages.
If the websocket connection underlying this RemoteEndpoint is busy sending a message when a call is made to send
another one, for example if two threads attempt to call a send method concurrently, or if a developer attempts to
send a new message while in the middle of sending an existing one, the send method called while the connection is
already busy may throw an java.lang.IllegalStateException.
| Modifier and Type | Method and Description |
|---|---|
| public OutputStream | Returns: the output stream to which the message will be written.Opens an output stream on which a binary message may be sent. |
| public Writer | Returns: the writer to which the message will be written.Opens a character stream on which a text message may be sent. |
| public void | sendBinary(ByteBuffer
the message to be sent. data)Send a binary message, returning when all of the message has been transmitted. |
| public void | sendBinary(ByteBuffer
the part of the message being sent. partialByte, boolean Whether the partial message being sent is the last part of the message. isLast)Send a binary message in parts, blocking until all of the message has been transmitted. |
| public void | sendObject(Object
the object to be sent. data)Sends a custom developer object, blocking until it has been transmitted. |
| public void | |
| public void |
| getSendStream | back to summary |
|---|---|
| public OutputStream getSendStream() throws IOException Opens an output stream on which a binary message may be sent. The developer must close the output stream in
order to indicate that the complete message has been placed into the output stream. If no calls are made to
one of the
| |
| getSendWriter | back to summary |
|---|---|
| public Writer getSendWriter() throws IOException Opens a character stream on which a text message may be sent. The developer must close the writer in order to
indicate that the complete message has been placed into the character stream. If no calls are made to one of
the
| |
| sendBinary | back to summary |
|---|---|
| public void sendBinary(ByteBuffer data) throws IOException Send a binary message, returning when all of the message has been transmitted. It is not safe for other threads to use the ByteBuffer until the sending of this message is complete. If the sending of the message completes successfully, the buffer's limit will be unchanged and the buffer's position will be equal to the limit. If the sending of the message does not complete successfully, the state of the buffer is undefined.
| |
| sendBinary | back to summary |
|---|---|
| public void sendBinary(ByteBuffer partialByte, boolean isLast) throws IOException Send a binary message in parts, blocking until all of the message has been transmitted. The runtime reads the message in order. Non-final parts are sent with isLast set to false. The final piece must be sent with isLast set to true. It is not safe for other threads to use the ByteBuffer until the sending of this partial message is complete. If the sending of the partial message completes successfully, the buffer's limit will be unchanged and the buffer's position will be equal to the limit. If the sending of the partial message does not complete successfully, the state of the buffer is undefined.
| |
| sendObject | back to summary |
|---|---|
| public void sendObject(Object data) throws IOException, EncodeException Sends a custom developer object, blocking until it has been transmitted. Containers will by default be able to encode java primitive types and their object equivalents, otherwise the developer must have provided an encoder for the object type in the endpoint configuration. A developer-provided encoder for a Java primitive type and its object equivalent overrides the container default encoder.
| |
| sendText | back to summary |
|---|---|
| public void sendText(String text) throws IOException Send a text message, blocking until all of the message has been transmitted.
| |
| sendText | back to summary |
|---|---|
| public void sendText(String partialMessage, boolean isLast) throws IOException Send a text message in parts, blocking until all of the message has been transmitted. The runtime reads the message in order. Non-final parts of the message are sent with isLast set to false. The final part must be sent with isLast set to true.
| |