[fix] 修复多客户端导致通道被移除问题

This commit is contained in:
wujiawei 2024-01-23 17:38:32 +08:00
parent fef8149ec4
commit 0382c300d7
3 changed files with 13 additions and 13 deletions

View File

@ -1,11 +1,11 @@
spring:
lazy:
netty:
inet-host: 127.0.0.1
inet-port: 7001
# inet-host: 127.0.0.1
# inet-port: 7001
# inet-path: middleground-on-cloud-heartbeat-server
# inet-host: 124.222.48.62 # 服务端地址
# inet-port: 30676 #服务端端口
inet-host: 124.222.48.62 # 服务端地址
inet-port: 30676 #服务端端口
# inet-path: middleground-on-cloud-heartbeat-server
client-id: wujiawei # 客户端ID
data:

View File

@ -52,7 +52,7 @@ public class ServerHandleClientConnectSuccessTypeAdvanced extends AbstractHandle
ChannelContext.push(newChannel, clientId);
ChannelAttributeKeyUtils.buildClientId(newChannel,clientId);
log.info("客户端:{}连接成功",new String(msg.getClientId()));
log.info("客户端:{}IP:{}连接成功",new String(msg.getClientId()),newChannel.remoteAddress().toString());
// 验证客户端是否时黑名单
NettyClientBlacklist nettyClientBlacklist = new NettyClientBlacklist();
nettyClientBlacklist.setClientId(clientId);

View File

@ -40,20 +40,20 @@ public class VisitorHandler extends SimpleChannelInboundHandler<ByteBuf> {
// 当前通道绑定访客ID
ChannelAttributeKeyUtils.buildVisitorId(visitorChannel, visitorId);
ChannelAttributeKeyUtils.buildClientId(visitorChannel, clientId);
NettyProxyMsg myMsg = new NettyProxyMsg();
myMsg.setType(MessageType.DISTRIBUTE_SINGLE_CLIENT_REAL_CONNECT);
myMsg.setClientId(clientId);
myMsg.setVisitorPort(visitorPort);
myMsg.setClientTargetIp(clientTargetIp);
myMsg.setClientTargetPort(clientTargetPort);
NettyProxyMsg nettyProxyMsg = new NettyProxyMsg();
nettyProxyMsg.setType(MessageType.DISTRIBUTE_SINGLE_CLIENT_REAL_CONNECT);
nettyProxyMsg.setClientId(clientId);
nettyProxyMsg.setVisitorPort(visitorPort);
nettyProxyMsg.setClientTargetIp(clientTargetIp);
nettyProxyMsg.setClientTargetPort(clientTargetPort);
myMsg.setVisitorId(visitorId);
nettyProxyMsg.setVisitorId(visitorId);
// 客户端心跳通道
ChannelContext.ClientChannel clientChannel = ChannelContext.get(clientId);
if (clientChannel != null) {
Channel channel = clientChannel.getChannel();
channel.writeAndFlush(myMsg);
channel.writeAndFlush(nettyProxyMsg);
}else {
log.error("无法通过客户端ID获取客户端通道");
}