Spring实战——使用WebSocket和STOMP实现消息功能(十一)

 

一、低层级的WebSocket API

WebSocket只是两个应用之间通信的通道。位于WebSocket一端的应用发送消息,另外一端处理消息。因为它是全双工的,所以每一端都可以发送和处理消息。

Spring实战——使用WebSocket和STOMP实现消息功能(十一)

 

服务端

Spring实战——使用WebSocket和STOMP实现消息功能(十一)

 

连接

Spring实战——使用WebSocket和STOMP实现消息功能(十一)

 

客户端

Spring实战——使用WebSocket和STOMP实现消息功能(十一)

 

 

 

 

 

二、应对不支持WebSocket的场景——SockJS

SockJS是WebSocket技术的一种模拟(备选方案),SockJS和WebSocket是独立的。

 

服务端

Spring实战——使用WebSocket和STOMP实现消息功能(十一)

 

连接

Spring实战——使用WebSocket和STOMP实现消息功能(十一)

 

客户端

Spring实战——使用WebSocket和STOMP实现消息功能(十一)

 

 

 

 

 

 三、使用STOMP消息

STOMP帧

Spring实战——使用WebSocket和STOMP实现消息功能(十一)

 

3.1 启用STOMP消息功能

启用STOMP消息功能

Spring实战——使用WebSocket和STOMP实现消息功能(十一)

 

启用STOMP代理中继

Spring实战——使用WebSocket和STOMP实现消息功能(十一)

 

3.2 处理来自客户端的STOMP消息

服务器端

Spring实战——使用WebSocket和STOMP实现消息功能(十一)

 

Spring实战——使用WebSocket和STOMP实现消息功能(十一)

 

客户端

Spring实战——使用WebSocket和STOMP实现消息功能(十一)

 

 

3.3 发送消息到客户端

 

自动返回

Spring实战——使用WebSocket和STOMP实现消息功能(十一)

Spring实战——使用WebSocket和STOMP实现消息功能(十一)

 

 

前端自动更新

Spring实战——使用WebSocket和STOMP实现消息功能(十一)

Spring实战——使用WebSocket和STOMP实现消息功能(十一)

 

 

 

 

四、为目标用户发送消息    P599

Spring实战——使用WebSocket和STOMP实现消息功能(十一)

 

Spring实战——使用WebSocket和STOMP实现消息功能(十一)