Class ClientWsConnection

java.lang.Object
io.helidon.webclient.websocket.ClientWsConnection
All Implemented Interfaces:
WsSession, Runnable

public class ClientWsConnection extends Object implements WsSession, Runnable
Client WebSocket connection. This connection handles a single WebSocket interaction, using WsListener to handle connection events.
  • Method Details

    • create

      public static ClientWsConnection create(ClientConnection clientConnection, WsListener listener, String subProtocol)
      Create a new connection. The connection needs to run on ana executor service (it implements Runnable) so it does not block the current thread.
      Parameters:
      clientConnection - connection to use for this WS connection
      listener - WebSocket listener to handle events on this connection
      subProtocol - chosen sub-protocol of this connection (negotiated during upgrade from HTTP/1)
      Returns:
      a new WebSocket connection
    • create

      public static ClientWsConnection create(ClientConnection clientConnection, WsListener listener)
      Create a new connection without a sub-protocol.
      Parameters:
      clientConnection - connection to work on
      listener - WebSocket listener to handle events on this connection
      Returns:
      a new WebSocket connection
    • run

      public void run()
      Specified by:
      run in interface Runnable
    • send

      public WsSession send(String text, boolean last)
      Description copied from interface: WsSession
      Send text fragment.
      Specified by:
      send in interface WsSession
      Parameters:
      text - text to send
      last - if last fragment
      Returns:
      this instance
    • send

      public WsSession send(BufferData bufferData, boolean last)
      Description copied from interface: WsSession
      Send binary fragment.
      Specified by:
      send in interface WsSession
      Parameters:
      bufferData - buffer with data
      last - if last fragment
      Returns:
      this instance
    • ping

      public WsSession ping(BufferData bufferData)
      Description copied from interface: WsSession
      Send ping.
      Specified by:
      ping in interface WsSession
      Parameters:
      bufferData - buffer with data
      Returns:
      this instance
    • pong

      public WsSession pong(BufferData bufferData)
      Description copied from interface: WsSession
      Send pong.
      Specified by:
      pong in interface WsSession
      Parameters:
      bufferData - buffer with data
      Returns:
      this instance
    • close

      public WsSession close(int code, String reason)
      Closes WebSocket session. If code is negative, then a CLOSE frame with no code or reason is sent. This can be used to test CLOSE frames with no payload, as required by the spec.
      Specified by:
      close in interface WsSession
      Parameters:
      code - close code, may be one of WsCloseCodes
      reason - reason description
      Returns:
      the session
    • terminate

      public WsSession terminate()
      Description copied from interface: WsSession
      Terminate session. Sends a close and closes the connection.
      Specified by:
      terminate in interface WsSession
      Returns:
      this instance
    • subProtocol

      public Optional<String> subProtocol()
      Description copied from interface: WsSession
      The WebSocket sub-protocol negotiated for this session.
      Specified by:
      subProtocol in interface WsSession
      Returns:
      sub-protocol negotiated, if any
    • socketContext

      public SocketContext socketContext()
      Description copied from interface: WsSession
      The underlying socket context.
      Specified by:
      socketContext in interface WsSession
      Returns:
      socket context