netty-确定客户端和微信端的沟通方式

This commit is contained in:
2023-08-22 21:35:57 +08:00
parent 86fd226c84
commit 6c0a07331b
24 changed files with 109 additions and 490 deletions

View File

@@ -1,13 +1,18 @@
package com.sv.netty;
import com.sv.netty.message.HeartBeat;
import com.sv.netty.config.HeartBeat;
import com.sv.netty.config.VenueMessage;
import com.sv.netty.utils.EncodeMsg;
import com.sv.netty.utils.JsonUtils;
import com.sv.service.MessageService;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.handler.timeout.IdleState;
import io.netty.handler.timeout.IdleStateEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.net.UnknownHostException;
@@ -19,6 +24,7 @@ import java.net.UnknownHostException;
*/
@ChannelHandler.Sharable
public class ClientHandler extends SimpleChannelInboundHandler<String> {
private final Logger logger = LoggerFactory.getLogger(ClientHandler.class);
/**
* 当通道就绪就会触发
@@ -48,9 +54,9 @@ public class ClientHandler extends SimpleChannelInboundHandler<String> {
*/
@Override
public void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception {
System.out.println("接收服务器响应msg:[" + msg + "]");
// MessageDTO message = JsonMapper.fromJson(msg, MessageDTO.class);
// MessageService.getInstance().execute(message);
logger.info("接收服务器响应msg:[" + msg + "]");
VenueMessage message = JsonUtils.decode(msg, VenueMessage.class);
MessageService.getInstance().execute(message);
}
/**
@@ -88,7 +94,7 @@ public class ClientHandler extends SimpleChannelInboundHandler<String> {
*/
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
System.out.println("ClientHandler exceptionCaught");
logger.info("ClientHandler exceptionCaught");
cause.printStackTrace();
Channel channel = ctx.channel();
if(channel.isActive()) {