org.springframework.web.reactive.socket

## Interface WebSocketSession

All Known Implementing Classes:
  AbstractListenerWebSocketSession, AbstractWebSocketSession, JettyWebSocketSession, NettyWebSocketSessionSupport, ReactorNettyWebSocketSession, StandardWebSocketSession, TomcatWebSocketSession, UndertowWebSocketSession

    public interface WebSocketSession

Represents a WebSocket session.

Use `session.receive()` to compose on the inbound message stream, and `session.send(publisher)` to provide the outbound message stream.

Since:
  5.0
Author:
  Rossen Stoyanchev

### Method Summary

All Methods Instance Methods Abstract Methods Default Methods
`WebSocketMessage` `binaryMessage(Function<org.springframework.core.io.buffer.DataBufferFactory,org.springframework.core.io.buffer.DataBuffer> payloadFactory)` Factory method to create a binary WebSocketMessage using the `bufferFactory()` for the session.
`org.springframework.core.io.buffer.DataBufferFactory` `bufferFactory()` Return a `DataBuffer` Factory to create message payloads.
`default reactor.core.publisher.Mono<Void>` `close()` Close the WebSocket session with `CloseStatus.NORMAL`.
`reactor.core.publisher.Mono<Void>` `close(CloseStatus status)` Close the WebSocket session with the given status.
`Map<String,Object>` `getAttributes()` Return the map with attributes associated with the WebSocket session.
`HandshakeInfo` `getHandshakeInfo()` Return information from the handshake request.
`String` `getId()` Return the id for the session.
`WebSocketMessage` `pingMessage(Function<org.springframework.core.io.buffer.DataBufferFactory,org.springframework.core.io.buffer.DataBuffer> payloadFactory)` Factory method to create a ping WebSocketMessage using the `bufferFactory()` for the session.
`WebSocketMessage` `pongMessage(Function<org.springframework.core.io.buffer.DataBufferFactory,org.springframework.core.io.buffer.DataBuffer> payloadFactory)` Factory method to create a pong WebSocketMessage using the `bufferFactory()` for the session.
`reactor.core.publisher.Flux<WebSocketMessage>` `receive()` Provides access to the stream of inbound messages.
`reactor.core.publisher.Mono<Void>` `send(org.reactivestreams.Publisher<WebSocketMessage> messages)` Give a source of outgoing messages, write the messages and return a `Mono<Void>` that completes when the source completes and writing is done.
`WebSocketMessage` `textMessage(String payload)` Factory method to create a text `WebSocketMessage` using the `bufferFactory()` for the session.

### Method Detail

#### getId

    String getId()

Return the id for the session.

#### getHandshakeInfo

    HandshakeInfo getHandshakeInfo()

Return information from the handshake request.

#### bufferFactory

    org.springframework.core.io.buffer.DataBufferFactory bufferFactory()

Return a `DataBuffer` Factory to create message payloads.

Returns:
  the buffer factory for the session

#### getAttributes

    Map<String,Object> getAttributes()

Return the map with attributes associated with the WebSocket session.

Returns:
  a Map with the session attributes (never `null`)
Since:
  5.1

#### receive

    reactor.core.publisher.Flux<WebSocketMessage> receive()

Provides access to the stream of inbound messages.

This stream receives a completion or error signal when the connection is closed. In a typical `WebSocketHandler` implementation this stream is composed into the overall processing flow, so that when the connection is closed, handling will end.

See the class-level doc of `WebSocketHandler` and the reference for more details and examples of how to handle the session.

#### send

    reactor.core.publisher.Mono<Void> send(org.reactivestreams.Publisher<WebSocketMessage> messages)

Give a source of outgoing messages, write the messages and return a `Mono<Void>` that completes when the source completes and writing is done.

See the class-level doc of `WebSocketHandler` and the reference for more details and examples of how to handle the session.

#### close

    default reactor.core.publisher.Mono<Void> close()

Close the WebSocket session with `CloseStatus.NORMAL`.

#### close

    reactor.core.publisher.Mono<Void> close(CloseStatus status)

Close the WebSocket session with the given status.

Parameters:
  `status` - the close status

#### textMessage

    WebSocketMessage textMessage(String payload)

Factory method to create a text `WebSocketMessage` using the `bufferFactory()` for the session.

#### binaryMessage

    WebSocketMessage binaryMessage(Function<org.springframework.core.io.buffer.DataBufferFactory,org.springframework.core.io.buffer.DataBuffer> payloadFactory)

Factory method to create a binary WebSocketMessage using the `bufferFactory()` for the session.

#### pingMessage

    WebSocketMessage pingMessage(Function<org.springframework.core.io.buffer.DataBufferFactory,org.springframework.core.io.buffer.DataBuffer> payloadFactory)

Factory method to create a ping WebSocketMessage using the `bufferFactory()` for the session.

#### pongMessage

    WebSocketMessage pongMessage(Function<org.springframework.core.io.buffer.DataBufferFactory,org.springframework.core.io.buffer.DataBuffer> payloadFactory)

Factory method to create a pong WebSocketMessage using the `bufferFactory()` for the session.