public interface MuWebSocketSession
A web socket session used to send messages and events to a web socket client.
The simplest way to get a reference to a session is to extend BaseWebSocket
and use the BaseWebSocket.session()
method.
Modifier and Type | Method and Description |
---|---|
void |
close()
Initiates a graceful shutdown with the client.
|
void |
close(int statusCode,
String reason)
Initiates a graceful shutdown with the client.
|
InetSocketAddress |
remoteAddress() |
void |
sendBinary(ByteBuffer message,
DoneCallback doneCallback)
Sends a message to the client
|
void |
sendPing(ByteBuffer payload,
DoneCallback doneCallback)
Sends a ping message to the client, which is used for keeping sockets alive.
|
void |
sendPong(ByteBuffer payload,
DoneCallback doneCallback)
Sends a pong message to the client, generally in response to receiving a ping via
MuWebSocket.onPing(ByteBuffer, DoneCallback) |
void |
sendText(String message,
DoneCallback doneCallback)
Sends a message to the client asynchronously
|
WebsocketSessionState |
state() |
void sendText(String message, DoneCallback doneCallback)
message
- The message to be sentdoneCallback
- The callback to call when the write succeeds or fails. To ignore the write result, you can
use DoneCallback.NoOp
. If using a buffer received from a MuWebSocket
event,
pass the onComplete
received to this parameter.void sendBinary(ByteBuffer message, DoneCallback doneCallback)
message
- The message to be sentdoneCallback
- The callback to call when the write succeeds or fails. To ignore the write result, you can
use DoneCallback.NoOp
. If using a buffer received from a MuWebSocket
event,
pass the onComplete
received to this parameter.void sendPing(ByteBuffer payload, DoneCallback doneCallback)
payload
- The message to send.doneCallback
- The callback to call when the write succeeds or fails. To ignore the write result, you can
use DoneCallback.NoOp
. If using a buffer received from a MuWebSocket
event,
pass the onComplete
received to this parameter.void sendPong(ByteBuffer payload, DoneCallback doneCallback)
MuWebSocket.onPing(ByteBuffer, DoneCallback)
payload
- The payload to send back to the client.doneCallback
- The callback to call when the write succeeds or fails. To ignore the write result, you can
use DoneCallback.NoOp
. If using a buffer received from a MuWebSocket
event,
pass the onComplete
received to this parameter.void close() throws IOException
IOException
- Thrown if there is an error writing to the client, for example if the user has closed their browser.void close(int statusCode, String reason) throws IOException
statusCode
- The status code to send, such as 1000
. See https://tools.ietf.org/html/rfc6455#section-7.4reason
- An optional reason for closing.IOException
- Thrown if there is an error writing to the client, for example if the user has closed their browser.InetSocketAddress remoteAddress()
WebsocketSessionState state()
Copyright © 2017–2021. All rights reserved.