Package io.muserver
Interface MuWebSocketSession
-
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 theBaseWebSocket.session()
method.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
close()
Initiates a graceful shutdown with the client.void
close(int statusCode, java.lang.String reason)
Initiates a graceful shutdown with the client.java.net.InetSocketAddress
remoteAddress()
void
sendBinary(java.nio.ByteBuffer message, boolean isLastFragment, DoneCallback doneCallback)
Sends a full or partial message to the client asynchronously with an optional parameter allowing partial fragments to be sentvoid
sendBinary(java.nio.ByteBuffer message, DoneCallback doneCallback)
Sends a message to the client asynchronouslyvoid
sendPing(java.nio.ByteBuffer payload, DoneCallback doneCallback)
Sends a ping message to the client, which is used for keeping sockets alive.void
sendPong(java.nio.ByteBuffer payload, DoneCallback doneCallback)
Sends a pong message to the client, generally in response to receiving a ping viaMuWebSocket.onPing(ByteBuffer, DoneCallback)
void
sendText(java.lang.String message, boolean isLastFragment, DoneCallback doneCallback)
Sends a full or partial message to the client asynchronously with an optional parameter allowing partial fragments to be sentvoid
sendText(java.lang.String message, DoneCallback doneCallback)
Sends a message to the client asynchronouslyWebsocketSessionState
state()
-
-
-
Method Detail
-
sendText
void sendText(java.lang.String message, DoneCallback doneCallback)
Sends a message to the client asynchronously- Parameters:
message
- The message to be sentdoneCallback
- The callback to call when the write succeeds or fails. To ignore the write result, you can useDoneCallback.NoOp
. If using a buffer received from aMuWebSocket
event, pass theonComplete
received to this parameter.
-
sendText
void sendText(java.lang.String message, boolean isLastFragment, DoneCallback doneCallback)
Sends a full or partial message to the client asynchronously with an optional parameter allowing partial fragments to be sent- Parameters:
message
- The message to be sentisLastFragment
- Iffalse
then this message will be sent as a partial fragmentdoneCallback
- The callback to call when the write succeeds or fails. To ignore the write result, you can useDoneCallback.NoOp
. If using a buffer received from aMuWebSocket
event, pass theonComplete
received to this parameter.
-
sendBinary
void sendBinary(java.nio.ByteBuffer message, DoneCallback doneCallback)
Sends a message to the client asynchronously- Parameters:
message
- The message to be sentdoneCallback
- The callback to call when the write succeeds or fails. To ignore the write result, you can useDoneCallback.NoOp
. If using a buffer received from aMuWebSocket
event, pass theonComplete
received to this parameter.
-
sendBinary
void sendBinary(java.nio.ByteBuffer message, boolean isLastFragment, DoneCallback doneCallback)
Sends a full or partial message to the client asynchronously with an optional parameter allowing partial fragments to be sent- Parameters:
message
- The message to be sentisLastFragment
- Iffalse
then this message will be sent as a partial fragmentdoneCallback
- The callback to call when the write succeeds or fails. To ignore the write result, you can useDoneCallback.NoOp
. If using a buffer received from aMuWebSocket
event, pass theonComplete
received to this parameter.
-
sendPing
void sendPing(java.nio.ByteBuffer payload, DoneCallback doneCallback)
Sends a ping message to the client, which is used for keeping sockets alive.- Parameters:
payload
- The message to send.doneCallback
- The callback to call when the write succeeds or fails. To ignore the write result, you can useDoneCallback.NoOp
. If using a buffer received from aMuWebSocket
event, pass theonComplete
received to this parameter.
-
sendPong
void sendPong(java.nio.ByteBuffer payload, DoneCallback doneCallback)
Sends a pong message to the client, generally in response to receiving a ping viaMuWebSocket.onPing(ByteBuffer, DoneCallback)
- Parameters:
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 useDoneCallback.NoOp
. If using a buffer received from aMuWebSocket
event, pass theonComplete
received to this parameter.
-
close
void close() throws java.io.IOException
Initiates a graceful shutdown with the client.- Throws:
java.io.IOException
- Thrown if there is an error writing to the client, for example if the user has closed their browser.
-
close
void close(int statusCode, java.lang.String reason) throws java.io.IOException
Initiates a graceful shutdown with the client.- Parameters:
statusCode
- The status code to send, such as1000
. See https://tools.ietf.org/html/rfc6455#section-7.4reason
- An optional reason for closing.- Throws:
java.io.IOException
- Thrown if there is an error writing to the client, for example if the user has closed their browser.
-
remoteAddress
java.net.InetSocketAddress remoteAddress()
- Returns:
- The client's address
-
state
WebsocketSessionState state()
- Returns:
- The state of the current session
-
-