Package io.muserver
Interface MuWebSocketSession
-
public interface MuWebSocketSessionA 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
BaseWebSocketand use theBaseWebSocket.session()method.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidclose()Initiates a graceful shutdown with the client.voidclose(int statusCode, java.lang.String reason)Initiates a graceful shutdown with the client.java.net.InetSocketAddressremoteAddress()voidsendBinary(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 sentvoidsendBinary(java.nio.ByteBuffer message, DoneCallback doneCallback)Sends a message to the client asynchronouslyvoidsendPing(java.nio.ByteBuffer payload, DoneCallback doneCallback)Sends a ping message to the client, which is used for keeping sockets alive.voidsendPong(java.nio.ByteBuffer payload, DoneCallback doneCallback)Sends a pong message to the client, generally in response to receiving a ping viaMuWebSocket.onPing(ByteBuffer, DoneCallback)voidsendText(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 sentvoidsendText(java.lang.String message, DoneCallback doneCallback)Sends a message to the client asynchronouslyWebsocketSessionStatestate()
-
-
-
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 aMuWebSocketevent, pass theonCompletereceived 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- Iffalsethen 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 aMuWebSocketevent, pass theonCompletereceived 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 aMuWebSocketevent, pass theonCompletereceived 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- Iffalsethen 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 aMuWebSocketevent, pass theonCompletereceived 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 aMuWebSocketevent, pass theonCompletereceived 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 aMuWebSocketevent, pass theonCompletereceived to this parameter.
-
close
void close() throws java.io.IOExceptionInitiates 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.IOExceptionInitiates 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
-
-