28 lines
804 B
Java
28 lines
804 B
Java
package com.ruoyi.api.controller;
|
|
|
|
import com.ruoyi.common.core.domain.AjaxResult;
|
|
import com.ruoyi.tcp.TcpServerManager;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
@RestController
|
|
@RequestMapping("/api/tcp")
|
|
public class TcpServerController {
|
|
private final TcpServerManager manager;
|
|
|
|
public TcpServerController(TcpServerManager manager) {
|
|
this.manager = manager;
|
|
}
|
|
|
|
@GetMapping("/status")
|
|
public AjaxResult status() {
|
|
return AjaxResult.success(manager.status());
|
|
}
|
|
|
|
@PostMapping("/send/{channel}")
|
|
public AjaxResult send(@PathVariable String channel, @RequestBody String message) {
|
|
boolean ok = manager.broadcast(channel, message);
|
|
if (ok) return AjaxResult.success();
|
|
return AjaxResult.error("channel not found");
|
|
}
|
|
}
|