接口 WebSocketSession
- 所有已知实现类:
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, andsession.send(publisher)to provide the outbound message stream.- 从以下版本开始:
- 5.0
- 作者:
- Rossen Stoyanchev
方法概要
所有方法 实例方法 抽象方法 默认方法 修饰符和类型 方法 说明 WebSocketMessagebinaryMessage(Function<DataBufferFactory,DataBuffer> payloadFactory)Factory method to create a binary WebSocketMessage using thebufferFactory()for the session.DataBufferFactorybufferFactory()Return aDataBufferFactory to create message payloads.default reactor.core.publisher.Mono<Void>close()Close the WebSocket session withCloseStatus.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.HandshakeInfogetHandshakeInfo()Return information from the handshake request.StringgetId()Return the id for the session.WebSocketMessagepingMessage(Function<DataBufferFactory,DataBuffer> payloadFactory)Factory method to create a ping WebSocketMessage using thebufferFactory()for the session.WebSocketMessagepongMessage(Function<DataBufferFactory,DataBuffer> payloadFactory)Factory method to create a pong WebSocketMessage using thebufferFactory()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 aMono<Void>that completes when the source completes and writing is done.WebSocketMessagetextMessage(String payload)Factory method to create a textWebSocketMessageusing thebufferFactory()for the session.
方法详细资料
getHandshakeInfo
HandshakeInfo getHandshakeInfo()
Return information from the handshake request.
bufferFactory
DataBufferFactory bufferFactory()
Return aDataBufferFactory to create message payloads.- 返回:
- the buffer factory for the session
getAttributes
Map<String,Object> getAttributes()
Return the map with attributes associated with the WebSocket session.- 返回:
- a Map with the session attributes (never
null) - 从以下版本开始:
- 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
WebSocketHandlerimplementation 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
WebSocketHandlerand 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 aMono<Void>that completes when the source completes and writing is done.See the class-level doc of
WebSocketHandlerand 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 withCloseStatus.NORMAL.
close
reactor.core.publisher.Mono<Void> close(CloseStatus status)
Close the WebSocket session with the given status.- 参数:
status- the close status
textMessage
WebSocketMessage textMessage(String payload)
Factory method to create a textWebSocketMessageusing thebufferFactory()for the session.
binaryMessage
WebSocketMessage binaryMessage(Function<DataBufferFactory,DataBuffer> payloadFactory)
Factory method to create a binary WebSocketMessage using thebufferFactory()for the session.
pingMessage
WebSocketMessage pingMessage(Function<DataBufferFactory,DataBuffer> payloadFactory)
Factory method to create a ping WebSocketMessage using thebufferFactory()for the session.
pongMessage
WebSocketMessage pongMessage(Function<DataBufferFactory,DataBuffer> payloadFactory)
Factory method to create a pong WebSocketMessage using thebufferFactory()for the session.