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 the BaseWebSocket.session() method.

    • Method Detail

      • sendText

        void sendText​(java.lang.String message,
                      DoneCallback doneCallback)
        Sends a message to the client asynchronously
        Parameters:
        message - The message to be sent
        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.
      • sendBinary

        void sendBinary​(java.nio.ByteBuffer message,
                        DoneCallback doneCallback)
        Sends a message to the client
        Parameters:
        message - The message to be sent
        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.
      • 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 use DoneCallback.NoOp. If using a buffer received from a MuWebSocket event, pass the onComplete 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 via MuWebSocket.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 use DoneCallback.NoOp. If using a buffer received from a MuWebSocket event, pass the onComplete 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 as 1000. See https://tools.ietf.org/html/rfc6455#section-7.4
        reason - 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