测试提交

This commit is contained in:
2024-12-18 09:38:13 +08:00
parent 441d2fb39b
commit 31a46b8df6
4 changed files with 14 additions and 9 deletions

View File

@@ -25,7 +25,8 @@ public enum SourceResponseCodeEnum {
UNABLE_TO_RESPOND(10529, "源状态有误,无法响应报文(例如源处于输出状态,无法响应初始化报文)"), UNABLE_TO_RESPOND(10529, "源状态有误,无法响应报文(例如源处于输出状态,无法响应初始化报文)"),
RE_OPERATE(10552,"重复的初始化操作") RE_OPERATE(10552,"重复的初始化操作"),
SOCKET_ERROR(20000,"连接服务端失败")

View File

@@ -6,7 +6,7 @@ import org.apache.poi.ss.formula.functions.T;
@Data @Data
public class WebSocketVO { public class WebSocketVO {
private String code; private Integer code;
private String message; private String message;

View File

@@ -1,8 +1,11 @@
package com.njcn.gather.detection.util.socket.cilent; package com.njcn.gather.detection.util.socket.cilent;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.njcn.common.pojo.enums.response.CommonResponseEnum; import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.exception.BusinessException; import com.njcn.common.pojo.exception.BusinessException;
import com.njcn.gather.detection.pojo.enums.SourceResponseCodeEnum;
import com.njcn.gather.detection.pojo.vo.WebSocketVO;
import com.njcn.gather.detection.util.socket.SocketManager; import com.njcn.gather.detection.util.socket.SocketManager;
import com.njcn.gather.detection.util.socket.WebServiceManager; import com.njcn.gather.detection.util.socket.WebServiceManager;
import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.Bootstrap;
@@ -49,7 +52,7 @@ public class NettyClient {
ch.pipeline() ch.pipeline()
//空闲状态的handler //空闲状态的handler
// 添加LineBasedFrameDecoder来按行分割数据 // 添加LineBasedFrameDecoder来按行分割数据
.addLast(new LineBasedFrameDecoder(1024)) .addLast(new LineBasedFrameDecoder(10240))
// .addLast(new IdleStateHandler(10, 0, 0, TimeUnit.SECONDS)) // .addLast(new IdleStateHandler(10, 0, 0, TimeUnit.SECONDS))
.addLast(new StringDecoder(CharsetUtil.UTF_8)) .addLast(new StringDecoder(CharsetUtil.UTF_8))
.addLast(new StringEncoder(CharsetUtil.UTF_8)) .addLast(new StringEncoder(CharsetUtil.UTF_8))
@@ -65,14 +68,15 @@ public class NettyClient {
} }
}); });
} catch (Exception e) { } catch (Exception e) {
System.out.println("进入异常............"); System.out.println("连接socker服务端发送异常............"+e.getMessage());
e.printStackTrace();
group.shutdownGracefully(); group.shutdownGracefully();
//TODO 通知页面 //TODO 通知页面
WebSocketVO webSocketVO = new WebSocketVO();
webSocketVO.setCode(SourceResponseCodeEnum.SOCKET_ERROR.getCode());
webSocketVO.setMessage(SourceResponseCodeEnum.SOCKET_ERROR.getMessage());
WebServiceManager.sendMsg(userPageId, JSON.toJSONString(webSocketVO));
}finally { }finally {
System.out.println("进入clientSocket最后步骤---------------------"); // System.out.println("进入clientSocket最后步骤---------------------");
} }
} }

View File

@@ -51,7 +51,7 @@ public class NettyDevClientHandler extends SimpleChannelInboundHandler<String> {
*/ */
@Override @Override
protected void channelRead0(ChannelHandlerContext ctx, String msg) throws InterruptedException { protected void channelRead0(ChannelHandlerContext ctx, String msg) throws InterruptedException {
System.out.println("接收server端数据>>>>>>"+msg); System.out.println("devhandler接收server端数据>>>>>>"+msg);
socketResponseService.deal(webUser,msg); socketResponseService.deal(webUser,msg);