Package ej.websocket

Interface Endpoint

  • All Known Implementing Classes:
    EndpointAdapter

    public interface Endpoint
    An Endpoint knows how to handle high level websocket events. It is responsible for the applicative reactions.

    An Endpoint defines callbacks that a WebSocket can use to handle high level events.

    • Method Detail

      • onBinaryMessage

        byte[] onBinaryMessage​(WebSocket ws,
                               byte[] message)
        A binary message has been received.

        If the return value is not null, then it is sent to the remote endpoint.

        Parameters:
        ws - the WebSocket on which the event occurred
        message - the received message
        Returns:
        a return message that the WebSocket will send to the remote endpoint
      • onClose

        void onClose​(WebSocket ws,
                     ReasonForClosure closeReason)
        The associated WebSocket is about to close. This method is called if the remote endpoint started a closing handshake (that is, a close control frame has been received and connection state was OPEN), or if the local application request to close the connection.

        The underlying socket connection may already be closed to you should not try to send any further message in this callback.

        Parameters:
        ws - the WebSocket about to be closed
        closeReason - the reason for closing
      • onOpen

        void onOpen​(WebSocket ws)
        The connection has been established.
        Parameters:
        ws - the WebSocket on which the event occurred
      • onPong

        void onPong​(byte[] data)
        A pong frame has been received.
        Parameters:
        data - the data received in the pong payload
      • onPing

        void onPing​(byte[] data)
        A ping frame has been received. The pong frame does not need to be sent manually, it will be done automatically by the websocket.
        Parameters:
        data - the data received in the ping payload
      • onTextMessage

        String onTextMessage​(WebSocket ws,
                             String message)
        A text message has been received.

        If the return value is not null, then it is sent to the remote endpoint.

        Parameters:
        ws - the WebSocket on which the event occurred
        message - the received message
        Returns:
        a return message that the WebSocket will send to the remote endpoint