Class WebSocketAdapter

All Implemented Interfaces:
WebSocketConnectionListener, WebSocketListener

public class WebSocketAdapter extends Object implements WebSocketListener
Default implementation of the WebSocketListener.

Convenient abstract class to base standard WebSocket implementations off of.

  • Constructor Details

    • WebSocketAdapter

      public WebSocketAdapter()
  • Method Details

    • getRemote

      public RemoteEndpoint getRemote()
    • getSession

      public Session getSession()
    • isConnected

      public boolean isConnected()
    • isNotConnected

      public boolean isNotConnected()
    • onWebSocketBinary

      public void onWebSocketBinary(byte[] payload, int offset, int len)
      Description copied from interface: WebSocketListener
      A WebSocket binary frame has been received.
      Specified by:
      onWebSocketBinary in interface WebSocketListener
      payload - the raw payload array received
      offset - the offset in the payload array where the data starts
      len - the length of bytes in the payload
    • onWebSocketClose

      public void onWebSocketClose(int statusCode, String reason)
      Description copied from interface: WebSocketConnectionListener
      A Close Event was received.

      The underlying Connection will be considered closed at this point.

      Specified by:
      onWebSocketClose in interface WebSocketConnectionListener
      statusCode - the close status code. (See StatusCode)
      reason - the optional reason for the close.
    • onWebSocketConnect

      public void onWebSocketConnect(Session sess)
      Description copied from interface: WebSocketConnectionListener
      A WebSocket Session has connected successfully and is ready to be used.

      Note: It is a good idea to track this session as a field in your object so that you can write messages back via the RemoteEndpoint

      Specified by:
      onWebSocketConnect in interface WebSocketConnectionListener
      sess - the websocket session.
    • onWebSocketError

      public void onWebSocketError(Throwable cause)
      Description copied from interface: WebSocketConnectionListener
      A WebSocket exception has occurred.

      This is a way for the internal implementation to notify of exceptions occured during the processing of websocket.

      Usually this occurs from bad / malformed incoming packets. (example: bad UTF8 data, frames that are too big, violations of the spec)

      This will result in the Session being closed by the implementing side.

      Specified by:
      onWebSocketError in interface WebSocketConnectionListener
      cause - the error that occurred.
    • onWebSocketText

      public void onWebSocketText(String message)
      Description copied from interface: WebSocketListener
      A WebSocket Text frame was received.
      Specified by:
      onWebSocketText in interface WebSocketListener
      message - the message