Interface BaseWebSocketExchange<A extends ExchangeContext>

Type Parameters:
A - the type of the exchange context
All Known Subinterfaces:
Web2SocketExchange<A>, WebSocketExchange<A>, WebSocketExchange<A>

public interface BaseWebSocketExchange<A extends ExchangeContext>

Represents a WebSocket exchange between a client and a server.

A WebSocket exchange is bidirectional and as a result provided an BaseWebSocketExchange.Inbound and an BaseWebSocketExchange.Outbound exposing WebSocket frames and messages respectively received and sent by a client or a server.

A WebSocket exchange can be created from an HTTP server exchange once the WebSocket opening handshake has completed or from an HTTP client to open a WebSocket connection to an HTTP server.

Since:
1.5
Author:
Jeremy Kuhn
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static interface 
    Represents the inbound part of a WebSocket exchange.
    static interface 
    Represents the outbound part of a WebSocket exchange.
  • Method Summary

    Modifier and Type
    Method
    Description
    default void
    Closes the WebSocket with the normal status (1000).
    default void
    close(short code)
    Closes the WebSocket with the specified status code.
    void
    close(short code, String reason)
    Closes the WebSocket with specified status code and reason.
    default void
    Closes the WebSocket with the specified status.
    default void
    close(WebSocketStatus status, String reason)
    Closes the WebSocket with specified status and reason.
    default void
    close(String reason)
    Closes the WebSocket with the normal status (1000) and the specified reason.
    Returns the context attached to the exchange.
    finalizer(Mono<Void> finalizer)
    Specifies a finalizer to the WebSocket exchange which completes once the exchange is closed.
    Returns the subprotocol that was negotiated with the client during the opening handshake.
    Returns the inbound part of the WebSocket exchange.
    Returns the outbound part of the WebSocket exchange.
  • Method Details

    • context

      A context()

      Returns the context attached to the exchange.

      Returns:
      the exchange context or null
    • getSubProtocol

      String getSubProtocol()

      Returns the subprotocol that was negotiated with the client during the opening handshake.

      Note that the handshake will fail and the WebSocket connection closed if no subprotocols could have been negotiated.

      Returns:
      a subprotocol or null if no subprotocol was specified by both client and server
    • inbound

      Returns the inbound part of the WebSocket exchange.

      This basically corresponds to the stream of WebSocket frames received by the server from the client or by the client from the server.

      Returns:
      the inbound part
    • outbound

      Returns the outbound part of the WebSocket exchange.

      This basically corresponds to the stream of WebSocket frames sent by the server to the client or by the client to the server.

      Returns:
      the outbound part
    • close

      default void close()

      Closes the WebSocket with the normal status (1000).

      If the WebSocket was already closed, this method does nothing.

    • close

      default void close(WebSocketStatus status)

      Closes the WebSocket with the specified status.

      If the WebSocket was already closed, this method does nothing.

      Parameters:
      status - a WebSocket close status
    • close

      default void close(short code)

      Closes the WebSocket with the specified status code.

      If the WebSocket was already closed, this method does nothing.

      Parameters:
      code - a WebSocket close status code
    • close

      default void close(String reason)

      Closes the WebSocket with the normal status (1000) and the specified reason.

      A WebSocket close frame must have a payload length of 125 bytes or less, when code + reason exceeds this limit, the reason shall be truncated.

      If the WebSocket was already closed, this method does nothing.

      Parameters:
      reason - a close reason
    • close

      default void close(WebSocketStatus status, String reason)

      Closes the WebSocket with specified status and reason.

      A WebSocket close frame must have a payload length of 125 bytes or less, when code + reason exceeds this limit, the reason shall be truncated.

      If the WebSocket was already closed, this method does nothing.

      Parameters:
      status - a WebSocket close status
      reason - a WebSocket close status code
    • close

      void close(short code, String reason)

      Closes the WebSocket with specified status code and reason.

      A WebSocket close frame must have a payload length of 125 bytes or less, when code + reason exceeds this limit, the reason shall be truncated.

      A WebSocket close frame must have a payload length of 125 bytes or less, when code + reason exceeds this limit, the reason shall be truncated.

      If the WebSocket was already closed, this method does nothing.

      Parameters:
      code - a WebSocket close status code
      reason - a WebSocket close status code
    • finalizer

      BaseWebSocketExchange<A> finalizer(Mono<Void> finalizer)

      Specifies a finalizer to the WebSocket exchange which completes once the exchange is closed.

      Parameters:
      finalizer - a finalizer
      Returns:
      the WebSocket exchange