org.springframework.web.socket
Interface WebSocketSession
所有已知子接口:
NativeWebSocketSession,SocketJsSession
所有已知實(shí)現(xiàn)類:
AbstractHttpSocketJsSession,AbstractSockJsSession,AbstractWebSocketSession,JettyWebSocketSession,PollingSockJsSession,StandardWebSocketSession,StreamingSockJsSession,WebSocketServerJsSession
-
public interface WebSocketSession
一個(gè)WebSocket的抽象, 允許通過WebSocket連接發(fā)送消息和關(guān)閉WebSocket連接. -
String getId()
返回唯一的session id -
URI getUri()
返回開啟WebSocekt連接的URI -
HttpHeaders getHandshakeHeaders()
返回握手請(qǐng)求的請(qǐng)求頭
HttpHeaders 封裝了各種頭信息
-
Map<String, Object> getHandshakeAttributes()
握手請(qǐng)求指定的屬性, 如何添加屬性查看HandshakeInterceptor -
Principal getPrincipal()
返回一個(gè)包含認(rèn)證用戶名稱的Principal實(shí)例, 如果用戶沒有被認(rèn)證, 則返回null -
InetSocketAddress getLocalAddress()
返回收到請(qǐng)求的(服務(wù)器)地址 -
InetSocketAddress getRemoteAddress()
返回遠(yuǎn)程客戶端地址 -
String getAcceptedProtocol()
返回協(xié)議的子協(xié)議, 如果沒有指定或者協(xié)議不成功則返回null.(先這樣翻譯, 有更好的私信我) -
List<WebSocketExtension> getExtensions()
返回協(xié)議擴(kuò)展, 如果沒有指定或者協(xié)議不成功則返回null.(同上) -
boolean isOpen()
返回連接是否打開 -
void sendMessage(Message<?> message) throws IOException
發(fā)送WebSocket消息, 可能是文本, 或者是二進(jìn)制 -
void close() throws IOException
關(guān)閉WebSocket連接, 狀態(tài)碼1000 -
void close(CloseStatus status) throws IOException
關(guān)閉WebSocket連接, 指定狀態(tài)碼status.
CloseStatus 包含了一大波狀態(tài)碼
參考資料: spring技術(shù)文檔