# WebSocket **Repository Path**: zcxn/web-socket ## Basic Information - **Project Name**: WebSocket - **Description**: SpringBoot 集成WebSocket demo - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 5 - **Created**: 2024-12-10 - **Last Updated**: 2024-12-10 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 使用教程 ## 启动项目 > 启动类: com.example.websocket.WebSocketApplication ## 开启三个浏览器窗口 > http://localhost:8081/demo/toWebSocketDemo/test1 > > http://localhost:8081/demo/toWebSocketDemo/test2 > > http://localhost:8081/demo/toWebSocketDemo/test3 ## 前端界面效果 ![image-20240428163731759](https://gitee.com/bruce6213/image/raw/master/image-20240428163731759.png) ## 后端日志打印 ![image-20240428163651913](https://gitee.com/bruce6213/image/raw/master/image-20240428163651913.png) # WebSocket ## 相关注解 ### @ServerEndpoint 将某个类声明成一个websocket服务端 ### @OnOpen 连接建立成功调用的方法,由前端new WebSocket触发 ### @OnMessage 收到客户端消息后调用的方法。由前端socket.send触发 ### @OnError 发生错误调用的方法 ### @OnClose 连接关闭调用的方法。由前端socket.close()触发 # 参考链接 [SpringBoot 集成WebSocket](https://blog.csdn.net/qq_42402854/article/details/130948270)