package org.example.websocket.controller;
|
|
import org.example.websocket.server.WsServer;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.web.bind.annotation.*;
|
|
/**
|
* @program: webSocketProject
|
* @description:
|
* @create: 2024-03-26 16:55
|
**/
|
@RestController
|
@RequestMapping("/api")
|
public class ReceptionController {
|
|
@Autowired
|
private WsServer wsServer;
|
|
@PostMapping("/sendNotification")
|
public void sendNotification(@RequestParam("message") String message) {
|
try {
|
System.out.println("接收到客户端推送消息:" + message);
|
// 全体发送
|
wsServer.sendMessageToAll(message);
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
}
|
|
}
|