diff --git a/detection/src/main/java/com/njcn/gather/detection/pojo/enums/SourceResponseCodeEnum.java b/detection/src/main/java/com/njcn/gather/detection/pojo/enums/SourceResponseCodeEnum.java index 9855431b..b98e288d 100644 --- a/detection/src/main/java/com/njcn/gather/detection/pojo/enums/SourceResponseCodeEnum.java +++ b/detection/src/main/java/com/njcn/gather/detection/pojo/enums/SourceResponseCodeEnum.java @@ -25,7 +25,8 @@ public enum SourceResponseCodeEnum { UNABLE_TO_RESPOND(10529, "源状态有误,无法响应报文(例如源处于输出状态,无法响应初始化报文)"), - RE_OPERATE(10552,"重复的初始化操作") + RE_OPERATE(10552,"重复的初始化操作"), + SOCKET_ERROR(20000,"连接服务端失败") diff --git a/detection/src/main/java/com/njcn/gather/detection/pojo/vo/WebSocketVO.java b/detection/src/main/java/com/njcn/gather/detection/pojo/vo/WebSocketVO.java index 38327c5f..3cdf1206 100644 --- a/detection/src/main/java/com/njcn/gather/detection/pojo/vo/WebSocketVO.java +++ b/detection/src/main/java/com/njcn/gather/detection/pojo/vo/WebSocketVO.java @@ -6,7 +6,7 @@ import org.apache.poi.ss.formula.functions.T; @Data public class WebSocketVO { - private String code; + private Integer code; private String message; diff --git a/detection/src/main/java/com/njcn/gather/detection/util/socket/cilent/NettyClient.java b/detection/src/main/java/com/njcn/gather/detection/util/socket/cilent/NettyClient.java index a28e0ea9..32adde6d 100644 --- a/detection/src/main/java/com/njcn/gather/detection/util/socket/cilent/NettyClient.java +++ b/detection/src/main/java/com/njcn/gather/detection/util/socket/cilent/NettyClient.java @@ -1,8 +1,11 @@ package com.njcn.gather.detection.util.socket.cilent; import cn.hutool.core.util.StrUtil; +import com.alibaba.fastjson.JSON; import com.njcn.common.pojo.enums.response.CommonResponseEnum; 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.WebServiceManager; import io.netty.bootstrap.Bootstrap; @@ -49,7 +52,7 @@ public class NettyClient { ch.pipeline() //空闲状态的handler // 添加LineBasedFrameDecoder来按行分割数据 - .addLast(new LineBasedFrameDecoder(1024)) + .addLast(new LineBasedFrameDecoder(10240)) // .addLast(new IdleStateHandler(10, 0, 0, TimeUnit.SECONDS)) .addLast(new StringDecoder(CharsetUtil.UTF_8)) .addLast(new StringEncoder(CharsetUtil.UTF_8)) @@ -65,14 +68,15 @@ public class NettyClient { } }); } catch (Exception e) { - System.out.println("进入异常............"); - e.printStackTrace(); + System.out.println("连接socker服务端发送异常............"+e.getMessage()); group.shutdownGracefully(); //TODO 通知页面 - - + WebSocketVO webSocketVO = new WebSocketVO(); + webSocketVO.setCode(SourceResponseCodeEnum.SOCKET_ERROR.getCode()); + webSocketVO.setMessage(SourceResponseCodeEnum.SOCKET_ERROR.getMessage()); + WebServiceManager.sendMsg(userPageId, JSON.toJSONString(webSocketVO)); }finally { - System.out.println("进入clientSocket最后步骤---------------------"); + // System.out.println("进入clientSocket最后步骤---------------------"); } } diff --git a/detection/src/main/java/com/njcn/gather/detection/util/socket/cilent/NettyDevClientHandler.java b/detection/src/main/java/com/njcn/gather/detection/util/socket/cilent/NettyDevClientHandler.java index 3a961a97..434315f4 100644 --- a/detection/src/main/java/com/njcn/gather/detection/util/socket/cilent/NettyDevClientHandler.java +++ b/detection/src/main/java/com/njcn/gather/detection/util/socket/cilent/NettyDevClientHandler.java @@ -51,7 +51,7 @@ public class NettyDevClientHandler extends SimpleChannelInboundHandler { */ @Override protected void channelRead0(ChannelHandlerContext ctx, String msg) throws InterruptedException { - System.out.println("接收server端数据>>>>>>"+msg); + System.out.println("devhandler接收server端数据>>>>>>"+msg); socketResponseService.deal(webUser,msg);