Top Description Methods
org.springframework.web.reactive.socket

public Interface WebSocketSession

Known Direct Implementers
org.springframework.web.reactive.socket.adapter.AbstractWebSocketSession
Imports
java.util.Map, java.util.function.Function, org.reactivestreams.Publisher, reactor.core.publisher.Flux, .Mono, org.springframework.core.io.buffer.DataBuffer, .DataBufferFactory

Represents a WebSocket session.

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

Author
Rossen Stoyanchev
Since
5.0

Method Summary

Modifier and TypeMethod and Description
public WebSocketMessage
binaryMessage(Function<DataBufferFactory, DataBuffer> payloadFactory)

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

public DataBufferFactory

Returns:

the buffer factory for the session
bufferFactory
()

Return a DataBuffer Factory to create message payloads.

public default Mono<Void>
close()

Close the WebSocket session with CloseStatus#NORMAL.

public Mono<Void>
close(CloseStatus
the close status
status
)

Close the WebSocket session with the given status.

public Mono<CloseStatus>
closeStatus()

Provides access to the CloseStatus with which the session is closed either locally or remotely, or completes empty if the session ended without a status.

public Map<String, Object>

Returns:

a Map with the session attributes (never null)
getAttributes
()

Return the map with attributes associated with the WebSocket session.

public HandshakeInfo
getHandshakeInfo()

Return information from the handshake request.

public String
getId()

Return the id for the session.

public boolean
isOpen()

Whether the underlying connection is open.

public WebSocketMessage
pingMessage(Function<DataBufferFactory, DataBuffer> payloadFactory)

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

public WebSocketMessage
pongMessage(Function<DataBufferFactory, DataBuffer> payloadFactory)

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

public Flux<WebSocketMessage>
receive()

Provides access to the stream of inbound messages.

public Mono<Void>
send(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.

public WebSocketMessage
textMessage(String payload)

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

Method Detail

binaryMessageback to summary
public WebSocketMessage binaryMessage(Function<DataBufferFactory, DataBuffer> payloadFactory)

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

bufferFactoryback to summary
public DataBufferFactory bufferFactory()

Return a DataBuffer Factory to create message payloads.

Returns:DataBufferFactory

the buffer factory for the session

closeback to summary
public default Mono<Void> close()

Close the WebSocket session with CloseStatus#NORMAL.

closeback to summary
public Mono<Void> close(CloseStatus status)

Close the WebSocket session with the given status.

Parameters
status:CloseStatus

the close status

closeStatusback to summary
public Mono<CloseStatus> closeStatus()

Provides access to the CloseStatus with which the session is closed either locally or remotely, or completes empty if the session ended without a status.

Since
5.3
getAttributesback to summary
public Map<String, Object> getAttributes()

Return the map with attributes associated with the WebSocket session.

Returns:Map<String, Object>

a Map with the session attributes (never null)

Since
5.1
getHandshakeInfoback to summary
public HandshakeInfo getHandshakeInfo()

Return information from the handshake request.

getIdback to summary
public String getId()

Return the id for the session.

isOpenback to summary
public boolean isOpen()

Whether the underlying connection is open.

Since
5.3.1
pingMessageback to summary
public WebSocketMessage pingMessage(Function<DataBufferFactory, DataBuffer> payloadFactory)

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

pongMessageback to summary
public WebSocketMessage pongMessage(Function<DataBufferFactory, DataBuffer> payloadFactory)

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

receiveback to summary
public 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.

sendback to summary
public Mono<Void> send(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.

textMessageback to summary
public WebSocketMessage textMessage(String payload)

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