Package org.eclipse.jetty.websocket.api
Interface RemoteEndpoint
- All Known Implementing Classes:
JettyWebSocketRemoteEndpoint
public interface RemoteEndpoint
-
Method Summary
Modifier and TypeMethodDescriptionvoid
flush()
Flushes messages that may have been batched by the implementation.int
Get the maximum number of data frames allowed to be waiting to be sent at any one time.Get the SocketAddress for the established connection.void
sendBytes
(ByteBuffer data) Send a binary message, returning when all bytes of the message has been transmitted.void
sendBytes
(ByteBuffer data, WriteCallback callback) Initiates the asynchronous transmission of a binary message.void
sendPartialBytes
(ByteBuffer fragment, boolean isLast) Send a binary message in pieces, blocking until all of the message has been transmitted.void
sendPartialBytes
(ByteBuffer fragment, boolean isLast, WriteCallback callback) Initiates the asynchronous transmission of a partial binary message.void
sendPartialString
(String fragment, boolean isLast) Send a text message in pieces, blocking until all of the message has been transmitted.void
sendPartialString
(String fragment, boolean isLast, WriteCallback callback) Initiates the asynchronous transmission of a partial text message.void
sendPing
(ByteBuffer applicationData) Send a Ping message containing the given application data to the remote endpoint, blocking until all of the message has been transmitted.void
sendPing
(ByteBuffer applicationData, WriteCallback callback) Asynchronously 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, this will block until all of the message has been transmitted.void
sendPong
(ByteBuffer applicationData, WriteCallback callback) Allows the developer to asynchronously send an unsolicited Pong message containing the given application data in order to serve as a unidirectional heartbeat for the session.void
sendString
(String text) Send a text message, blocking until all bytes of the message has been transmitted.void
sendString
(String text, WriteCallback callback) Initiates the asynchronous transmission of a text message.void
setBatchMode
(BatchMode mode) Set the batch mode with which messages are sent.void
setMaxOutgoingFrames
(int maxOutgoingFrames) Set the maximum number of data frames allowed to be waiting to be sent at any one time.
-
Method Details
-
sendBytes
Send a binary message, returning when all bytes of the message has been transmitted.Note: this is a blocking call
- Parameters:
data
- the message to be sent- Throws:
IOException
- if unable to send the bytes
-
sendBytes
Initiates the asynchronous transmission of a binary message. This method returns before the message is transmitted. Developers may provide a callback to be notified when the message has been transmitted or resulted in an error.- Parameters:
data
- the data being sentcallback
- callback to notify of success or failure of the write operation
-
sendPartialBytes
Send a binary message in pieces, blocking until all of the message has been transmitted. The runtime reads the message in order. Non-final pieces are sent with isLast set to false. The final piece must be sent with isLast set to true.- Parameters:
fragment
- the piece of the message being sentisLast
- true if this is the last piece of the partial bytes- Throws:
IOException
- if unable to send the partial bytes
-
sendPartialBytes
Initiates the asynchronous transmission of a partial binary message. This method returns before the message is transmitted. The runtime reads the message in order. Non-final pieces are sent with isLast set to false. The final piece must be sent with isLast set to true. Developers may provide a callback to be notified when the message has been transmitted or resulted in an error.- Parameters:
fragment
- the data being sentisLast
- true if this is the last piece of the partial bytescallback
- callback to notify of success or failure of the write operation
-
sendString
Send a text message, blocking until all bytes of the message has been transmitted.Note: this is a blocking call
- Parameters:
text
- the message to be sent- Throws:
IOException
- if unable to send the text message
-
sendString
Initiates the asynchronous transmission of a text message. This method may return before the message is transmitted. Developers may provide a callback to be notified when the message has been transmitted or resulted in an error.- Parameters:
text
- the text being sentcallback
- callback to notify of success or failure of the write operation
-
sendPartialString
Send a text message in pieces, blocking until all of the message has been transmitted. The runtime reads the message in order. Non-final pieces are sent with isLast set to false. The final piece must be sent with isLast set to true.- Parameters:
fragment
- the piece of the message being sentisLast
- true if this is the last piece of the partial bytes- Throws:
IOException
- if unable to send the partial bytes
-
sendPartialString
Initiates the asynchronous transmission of a partial text message. This method may return before the message is transmitted. The runtime reads the message in order. Non-final pieces are sent with isLast set to false. The final piece must be sent with isLast set to true. Developers may provide a callback to be notified when the message has been transmitted or resulted in an error.- Parameters:
fragment
- the text being sentisLast
- true if this is the last piece of the partial bytescallback
- callback to notify of success or failure of the write operation- Throws:
IOException
- this never throws IOException, it was a mistake to have this in the signature.
-
sendPing
Send a Ping message containing the given application data to the remote endpoint, blocking until all of the message has been transmitted. The corresponding Pong message may be picked up using the MessageHandler.Pong handler.- Parameters:
applicationData
- the data to be carried in the ping request- Throws:
IOException
- if unable to send the ping
-
sendPing
Asynchronously 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.- Parameters:
applicationData
- the data to be carried in the ping requestcallback
- callback to notify of success or failure of the write operation
-
sendPong
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, this will block until all of the message has been transmitted.- Parameters:
applicationData
- the application data to be carried in the pong response.- Throws:
IOException
- if unable to send the pong
-
sendPong
Allows the developer to asynchronously send an unsolicited Pong message containing the given application data in order to serve as a unidirectional heartbeat for the session.- Parameters:
applicationData
- the application data to be carried in the pong response.callback
- callback to notify of success or failure of the write operation
-
getBatchMode
BatchMode getBatchMode()- Returns:
- the batch mode with which messages are sent.
- See Also:
-
setBatchMode
Set the batch mode with which messages are sent.- Parameters:
mode
- the batch mode to use- See Also:
-
getMaxOutgoingFrames
int getMaxOutgoingFrames()Get the maximum number of data frames allowed to be waiting to be sent at any one time. The default value is -1, this indicates there is no limit on how many frames can be queued to be sent by the implementation. If the limit is exceeded, subsequent frames sent are failed with aWritePendingException
but the connection is not failed and will remain open.- Returns:
- the max number of frames.
-
setMaxOutgoingFrames
void setMaxOutgoingFrames(int maxOutgoingFrames) Set the maximum number of data frames allowed to be waiting to be sent at any one time. The default value is -1, this indicates there is no limit on how many frames can be queued to be sent by the implementation. If the limit is exceeded, subsequent frames sent are failed with aWritePendingException
but the connection is not failed and will remain open.- Parameters:
maxOutgoingFrames
- the max number of frames.
-
getRemoteAddress
SocketAddress getRemoteAddress()Get the SocketAddress for the established connection.- Returns:
- the SocketAddress for the established connection.
-
flush
Flushes messages that may have been batched by the implementation.- Throws:
IOException
- if the flush fails
-