接口 WebSocketSession
- 所有超级接口:
AutoCloseable
,Closeable
- 所有已知子接口:
NativeWebSocketSession
,SockJsSession
- 所有已知实现类:
AbstractClientSockJsSession
,AbstractHttpSockJsSession
,AbstractSockJsSession
,AbstractWebSocketSession
,ConcurrentWebSocketSessionDecorator
,JettyWebSocketSession
,PollingSockJsSession
,StandardWebSocketSession
,StreamingSockJsSession
,WebSocketClientSockJsSession
,WebSocketServerSockJsSession
,WebSocketSessionDecorator
,XhrClientSockJsSession
public interface WebSocketSession extends Closeable
A WebSocket session abstraction. Allows sending messages over a WebSocket connection and closing it.- 从以下版本开始:
- 4.0
- 作者:
- Rossen Stoyanchev
方法概要
所有方法 实例方法 抽象方法 修饰符和类型 方法 说明 void
close()
Close the WebSocket connection with status 1000, i.e. equivalent to:void
close(CloseStatus status)
Close the WebSocket connection with the given close status.String
getAcceptedProtocol()
Return the negotiated sub-protocol.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()
Determine the negotiated extensions.HttpHeaders
getHandshakeHeaders()
Return the headers used in the handshake request (nevernull
).String
getId()
Return a unique session identifier.InetSocketAddress
getLocalAddress()
Return the address on which the request was received.Principal
getPrincipal()
Return aPrincipal
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: eitherTextMessage
orBinaryMessage
.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.
方法详细资料
getHandshakeHeaders
HttpHeaders getHandshakeHeaders()
Return the headers used in the handshake request (nevernull
).
getAttributes
Map<String,Object> getAttributes()
Return the map with attributes associated with the WebSocket session.On the server side the map can be populated initially through a
HandshakeInterceptor
. On the client side the map can be populated viaWebSocketClient
handshake methods.- 返回:
- a Map with the session attributes (never
null
)
getPrincipal
Principal getPrincipal()
Return aPrincipal
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.- 返回:
- the protocol identifier, or
null
if no protocol 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()
Determine the negotiated extensions.- 返回:
- the list of extensions, or an empty list if no extension was specified or negotiated successfully
sendMessage
void sendMessage(WebSocketMessage<?> message) throws IOException
Send a WebSocket message: eitherTextMessage
orBinaryMessage
.Note: The underlying standard WebSocket session (JSR-356) does not allow concurrent sending. Therefore sending must be synchronized. To ensure that, one option is to wrap the
WebSocketSession
with theConcurrentWebSocketSessionDecorator
.
isOpen
boolean isOpen()
Return whether the connection is still open.
close
void close() throws IOException
Close the WebSocket connection with status 1000, i.e. equivalent to:session.close(CloseStatus.NORMAL);
- 指定者:
close
在接口中AutoCloseable
- 指定者:
close
在接口中Closeable
- 抛出:
IOException
close
void close(CloseStatus status) throws IOException
Close the WebSocket connection with the given close status.- 抛出:
IOException