diff --git a/cloud-central-control-client/src/main/java/com/cm/central/control/client/socket/handler/SocketClientHandler.java b/cloud-central-control-client/src/main/java/com/cm/central/control/client/socket/handler/SocketClientHandler.java index 70a6a3e..34c99f1 100644 --- a/cloud-central-control-client/src/main/java/com/cm/central/control/client/socket/handler/SocketClientHandler.java +++ b/cloud-central-control-client/src/main/java/com/cm/central/control/client/socket/handler/SocketClientHandler.java @@ -1,10 +1,13 @@ package com.cm.central.control.client.socket.handler; +import com.alibaba.fastjson.JSONObject; import com.cm.central.control.client.socket.config.properties.SocketClientProperties; import com.cm.central.control.client.socket.manager.SocketClientManager; import com.cm.central.control.client.socket.socket.SocketClientRunnable; +import com.cm.socket.enums.SocketCodeEnum; import com.cm.socket.enums.SocketTypeMessageEnum; import com.cm.socket.pojo.Message; +import com.cm.socket.pojo.SocketResult; import com.cm.socket.service.ISocketService; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.SimpleChannelInboundHandler; @@ -41,15 +44,24 @@ public class SocketClientHandler extends SimpleChannelInboundHandler { } @Override - protected void channelRead0(ChannelHandlerContext ctx, Message message) throws Exception { + protected void channelRead0(ChannelHandlerContext channelHandlerContext, Message message) throws Exception { if (message.getType() == SocketTypeMessageEnum.MESSAGE_TYPE_PONG.getType()) { - pingServiceImpl.readMessage(ctx, message); + pingServiceImpl.readMessage(channelHandlerContext, message); } else if (message.getType() == SocketTypeMessageEnum.MESSAGE_TYPE_CLIENT_LOGIN.getType()) { - loginServiceImpl.readMessage(ctx, message); + loginServiceImpl.readMessage(channelHandlerContext, message); } else if (message.getType() == SocketTypeMessageEnum.MESSAGE_TYPE_EXCEPTION.getType()) { - exceptionServiceImpl.readMessage(ctx, message); + exceptionServiceImpl.readMessage(channelHandlerContext, message); } else if (message.getType() == SocketTypeMessageEnum.MESSAGE_TYPE_ERROR.getType()) { - errorServiceImpl.readMessage(ctx, message); + errorServiceImpl.readMessage(channelHandlerContext, message); + } else { + SocketResult socketResult = new SocketResult<>(); + socketResult.setCode(SocketCodeEnum.ERROR.getCode()); + socketResult.setErrorMsg("消息类型暂不支持"); + Message resultMessage = new Message(); + resultMessage.setStart(SocketTypeMessageEnum.MESSAGE_TYPE_START.getType()); + resultMessage.setType(SocketTypeMessageEnum.MESSAGE_TYPE_ERROR.getType()); + resultMessage.setContent(JSONObject.toJSONString(socketResult)); + channelHandlerContext.channel().writeAndFlush(message); } } diff --git a/cloud-central-control/src/main/java/com/cm/central/control/handler/SocketServerHandler.java b/cloud-central-control/src/main/java/com/cm/central/control/handler/SocketServerHandler.java index d9222d8..83c6e98 100644 --- a/cloud-central-control/src/main/java/com/cm/central/control/handler/SocketServerHandler.java +++ b/cloud-central-control/src/main/java/com/cm/central/control/handler/SocketServerHandler.java @@ -1,8 +1,11 @@ package com.cm.central.control.handler; +import com.alibaba.fastjson.JSONObject; import com.cm.central.control.manager.SocketServerManager; +import com.cm.socket.enums.SocketCodeEnum; import com.cm.socket.enums.SocketTypeMessageEnum; import com.cm.socket.pojo.Message; +import com.cm.socket.pojo.SocketResult; import com.cm.socket.service.ISocketService; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.SimpleChannelInboundHandler; @@ -43,6 +46,15 @@ public class SocketServerHandler extends SimpleChannelInboundHandler { socketClientExceptionServiceImpl.readMessage(channelHandlerContext, message); } else if (message.getType() == SocketTypeMessageEnum.MESSAGE_TYPE_CLIENT_INFO.getType()) { socketClientInfoServiceImpl.readMessage(channelHandlerContext, message); + } else { + SocketResult socketResult = new SocketResult<>(); + socketResult.setCode(SocketCodeEnum.ERROR.getCode()); + socketResult.setErrorMsg("消息类型暂不支持"); + Message resultMessage = new Message(); + resultMessage.setStart(SocketTypeMessageEnum.MESSAGE_TYPE_START.getType()); + resultMessage.setType(SocketTypeMessageEnum.MESSAGE_TYPE_ERROR.getType()); + resultMessage.setContent(JSONObject.toJSONString(socketResult)); + channelHandlerContext.channel().writeAndFlush(message); } }