https://github.com/chgl16/websocket-broadcast
Spring Boot + WebSocket(STOMP) + Thymeleaf实现广播通讯
https://github.com/chgl16/websocket-broadcast
spring-boot thymeleaf websocket websocket-broadcast
Last synced: about 1 month ago
JSON representation
Spring Boot + WebSocket(STOMP) + Thymeleaf实现广播通讯
- Host: GitHub
- URL: https://github.com/chgl16/websocket-broadcast
- Owner: chgl16
- Created: 2018-12-13T15:56:23.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-12-13T16:05:42.000Z (over 7 years ago)
- Last Synced: 2025-11-14T11:15:37.500Z (7 months ago)
- Topics: spring-boot, thymeleaf, websocket, websocket-broadcast
- Language: Java
- Homepage:
- Size: 160 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# websocket-broadcast
WebSocket通过一个socket实现全双工异步通讯,对比HTTP基于请求应答的半双工通讯。
其在广播和点对点实时通讯方法更优越。
>直接使用WebSocket或者SockJS(WebSocket协议的模拟,兼容性要求高)会使开发车旭很繁琐。
>所以会直接使用它的子协议STOMP(Simple (or Streaming) Text Orientated Messaging Protocol)。
>STOMP协议使用一个基于帧(frame)的格式定义消息,与HTTP的request和response类似(具有类似@RequestMapping的@MessageMapping)
>注:学习自 **《JavaEE开发的颠覆者 Spring Boot实战》** 一书
#### 效果

>每个浏览器窗口输入localhost:8080即可。全站广播。
>简单原理:
> 1. 客户端连接服务器开放的socket(连接过程有个可选的订阅操作,订阅了就会收到广播,订阅函数是个异步回调函数)
> 2. 客户端发送要广播的数据给服务器,服务器@MessageMapping接收处理,然后返回给订阅的客户端。(这里的客户端同一份代码都是订阅的)
> 3. 客户端触发订阅的回调函数,处理广播数据。
#### 项目结构

#### [=>博客地址](https://blog.csdn.net/chenbetter1996/article/details/84996772)