package org.example.websocket.controller; import org.example.websocket.server.WsServer; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RestController; import java.io.IOException; /** * @ClassDescription: 服务端请求类 * @JdkVersion: 1.8 * @Created: 2023/8/31 16:51 */ @RestController public class WsServerController { @Autowired WsServer wsServer; /** * 服务端发消息给客户端 * @param message 消息 */ @PostMapping("/send2client") public void send2Client(@RequestBody String message) throws IOException { wsServer.sendMessageToAll(message); } }