org.springframework.web.socket

## Interface WebSocketSession

- All Known Subinterfaces:
    NativeWebSocketSession, SockJsSession
  All Known Implementing Classes:
    AbstractHttpSockJsSession, AbstractSockJsSession, AbstractWebSocketSession, ConcurrentWebSocketSessionDecorator, JettyWebSocketSession, PollingSockJsSession, StandardWebSocketSession, StreamingSockJsSession, WebSocketServerSockJsSession, WebSocketSessionDecorator

      public interface WebSocketSession

  A WebSocket session abstraction. Allows sending messages over a WebSocket connection and closing it.
  Since:
    4.0
  Author:
    Rossen Stoyanchev

- - ### Method Summary

    All Methods Instance Methods Abstract Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `close()` Close the WebSocket connection with status 1000, i.e.
    `void` | `close(CloseStatus status)` Close the WebSocket connection with the given close status.
    `String` | `getAcceptedProtocol()` Return the negotiated sub-protocol or `null` if none was specified or negotiated successfully.
    `Map<String,Object>` | `getAttributes()` Return the map with attributes associated with the WebSocket session.
    `int` | `getBinaryMessageSizeLimit()` Get the configured maximum size for an incoming binary message.
    `List<WebSocketExtension>` | `getExtensions()` Return the negotiated extensions or `null` if none was specified or negotiated successfully.
    `HttpHeaders` | `getHandshakeHeaders()` Return the headers used in the handshake request.
    `String` | `getId()` Return a unique session identifier.
    `InetSocketAddress` | `getLocalAddress()` Return the address on which the request was received.
    `Principal` | `getPrincipal()` Return a `Principal` instance containing the name of the authenticated user.
    `InetSocketAddress` | `getRemoteAddress()` Return the address of the remote client.
    `int` | `getTextMessageSizeLimit()` Get the configured maximum size for an incoming text message.
    `URI` | `getUri()` Return the URI used to open the WebSocket connection.
    `boolean` | `isOpen()` Return whether the connection is still open.
    `void` | `sendMessage(WebSocketMessage<?> message)` Send a WebSocket message either `TextMessage` or `BinaryMessage`.
    `void` | `setBinaryMessageSizeLimit(int messageSizeLimit)` Configure the maximum size for an incoming binary message.
    `void` | `setTextMessageSizeLimit(int messageSizeLimit)` Configure the maximum size for an incoming text message.

- - ### Method Detail

    - #### getId

          String getId()

      Return a unique session identifier.

    - #### getUri

          URI getUri()

      Return the URI used to open the WebSocket connection.

    - #### getHandshakeHeaders

          HttpHeaders getHandshakeHeaders()

      Return the headers used in the handshake request.

    - #### getAttributes

          Map<String,Object> getAttributes()

      Return the map with attributes associated with the WebSocket session.

      When the WebSocketSession is created, on the server side, the map can be through a `HandshakeInterceptor`. On the client side, the map can be populated by passing attributes to the `WebSocketClient` handshake methods.

    - #### getPrincipal

          Principal getPrincipal()

      Return a `Principal` instance containing the name of the authenticated user. If the user has not been authenticated, the method returns `null`.

    - #### getLocalAddress

          InetSocketAddress getLocalAddress()

      Return the address on which the request was received.

    - #### getRemoteAddress

          InetSocketAddress getRemoteAddress()

      Return the address of the remote client.

    - #### getAcceptedProtocol

          String getAcceptedProtocol()

      Return the negotiated sub-protocol or `null` if none was specified or negotiated successfully.

    - #### setTextMessageSizeLimit

          void setTextMessageSizeLimit(int messageSizeLimit)

      Configure the maximum size for an incoming text message.

    - #### getTextMessageSizeLimit

          int getTextMessageSizeLimit()

      Get the configured maximum size for an incoming text message.

    - #### setBinaryMessageSizeLimit

          void setBinaryMessageSizeLimit(int messageSizeLimit)

      Configure the maximum size for an incoming binary message.

    - #### getBinaryMessageSizeLimit

          int getBinaryMessageSizeLimit()

      Get the configured maximum size for an incoming binary message.

    - #### getExtensions

          List<WebSocketExtension> getExtensions()

      Return the negotiated extensions or `null` if none was specified or negotiated successfully.

    - #### isOpen

          boolean isOpen()

      Return whether the connection is still open.

    - #### sendMessage

          void sendMessage(WebSocketMessage<?> message)
                    throws IOException

      Send a WebSocket message either `TextMessage` or `BinaryMessage`.
      Throws:
        `IOException`

    - #### close

          void close()
              throws IOException

      Close the WebSocket connection with status 1000, i.e. equivalent to:

           session.close(CloseStatus.NORMAL);

      Throws:
        `IOException`

    - #### close

          void close(CloseStatus status)
              throws IOException

      Close the WebSocket connection with the given close status.
      Throws:
        `IOException`