package com.dy.pmsTest; import com.dy.common.webUtil.BaseResponse; import com.dy.pmsTest.tcpClient.TcpClUnit; import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import java.nio.charset.StandardCharsets; /** * @Author: liurunyu * @Date: 2024/8/16 14:48 * @Description */ @Slf4j @RestController @RequestMapping(path="ctrl") public class TestCtrl { @PostMapping(path = "sendMs") public BaseResponse sendMs(String txt) { BaseResponse rt = new BaseResponse<>() ; if(txt != null && !txt.trim().equals("")){ txt = txt + "\n" ; byte[] bs = txt.getBytes(StandardCharsets.UTF_8) ; TcpClUnit.session.write(bs) ; rt.setCode("1") ; rt.setMsg("已经发送数据:" + txt) ; rt.setSuccess(true) ; }else{ rt.setCode("1") ; rt.setMsg("请输入数据") ; rt.setSuccess(false) ; } return rt ; } }