# springboot-websocket **Repository Path**: congong_dev/springboot-websocket ## Basic Information - **Project Name**: springboot-websocket - **Description**: springboot整合websocket - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2023-05-31 - **Last Updated**: 2023-12-06 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # springboot搭建WebSocket服务 ## 客户端的使用 * 地址是 ws://localhost:8080 * 协议是ws * 端口和springboot端口相同 * url路径为注解配置 @ServerEndpoint("/websocket/{userId}"); 如果配置了server.servlet.context-path=/xxx,路径前缀需要添加/xxx,否则访问不到 ``` 全连接: ws://localhost:8080/websocket/{userId} 客户端先使用唯一表示(用户id)进行连接; 然后做监听,参考src/ws.html测试文件 然后客户端和服务端就可以互发消息了; ``` ## 测试服务端向客户端发送消息 测试类:com.congong.websocket.controller.TestController * 指定用户发送 /sendMessageByUser * 向所有用户发送 /sendAllMessage # 拿走就能用,不客气!