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 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 sent
      void sendBinary​(java.nio.ByteBuffer message, DoneCallback doneCallback)
      Sends a message to the client asynchronously
      void 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 via MuWebSocket.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 sent
      void sendText​(java.lang.String message, DoneCallback doneCallback)
      Sends a message to the client asynchronously
      WebsocketSessionState 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 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.
      • 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 sent
        isLastFragment - If false then this message will be sent as a partial fragment
        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 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,
                        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 sent
        isLastFragment - If false then this message will be sent as a partial fragment
        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