zj
2024-03-27 533f1b6ba44f398d1860a95e38589fbc13d60d44
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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;
 
/**
 * @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){
//        wsServer.sendMessageToAll("this is a test for server to client");
        wsServer.sendMessageToAll(message);
    }
 
}