[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: spring:
lazy: lazy:
netty: netty:
inet-host: 127.0.0.1 # inet-host: 127.0.0.1
inet-port: 7001 # inet-port: 7001
# inet-path: middleground-on-cloud-heartbeat-server # inet-path: middleground-on-cloud-heartbeat-server
# inet-host: 124.222.48.62 # 服务端地址 inet-host: 124.222.48.62 # 服务端地址
# inet-port: 30676 #服务端端口 inet-port: 30676 #服务端端口
# inet-path: middleground-on-cloud-heartbeat-server # inet-path: middleground-on-cloud-heartbeat-server
client-id: wujiawei # 客户端ID client-id: wujiawei # 客户端ID
data: data:

View File

@ -52,7 +52,7 @@ public class ServerHandleClientConnectSuccessTypeAdvanced extends AbstractHandle
ChannelContext.push(newChannel, clientId); ChannelContext.push(newChannel, clientId);
ChannelAttributeKeyUtils.buildClientId(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 nettyClientBlacklist = new NettyClientBlacklist();
nettyClientBlacklist.setClientId(clientId); nettyClientBlacklist.setClientId(clientId);

View File

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