public interface RemoteEndpoint
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 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 | Interface and Description |
---|---|
static interface |
RemoteEndpoint.Async
This representation of the peer of a web socket conversation has the ability
to send messages asynchronously.
|
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 |
---|---|
void |
flushBatch()
This method is only used when batching is allowed for this RemoteEndpint.
|
boolean |
getBatchingAllowed()
Return whether the implementation is allowed to batch outgoing messages
before sending.
|
void |
sendPing(ByteBuffer applicationData)
Send a Ping message containing the given application data to the remote endpoint.
|
void |
sendPong(ByteBuffer 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.
|
void |
setBatchingAllowed(boolean allowed)
Indicate to the implementation that it is allowed to batch outgoing messages
before sending.
|
void setBatchingAllowed(boolean allowed) throws IOException
allowed
- whether the implementation is allowed to batch messages.IOException
- if batching is being disabled and there are unsent messages
this error may be thrown as the implementation sends the batch of unsent messages if
there is a problem.boolean getBatchingAllowed()
setBatchingAllowed
.void flushBatch() throws IOException
IOException
void sendPing(ByteBuffer applicationData) throws IOException, IllegalArgumentException
applicationData
- the data to be carried in the ping request.IOException
- if the ping failed to be sentIllegalArgumentException
- if the applicationData exceeds the maximum allowed payload of 125 bytesvoid sendPong(ByteBuffer applicationData) throws IOException, IllegalArgumentException
applicationData
- the application data to be carried in the pong response.IOException
- if the pong failed to be sentIllegalArgumentException
- if the applicationData exceeds the maximum allowed payload of 125 bytesCopyright © 2019 JBoss by Red Hat. All rights reserved.