channel工具类

This commit is contained in:
Guoqs
2024-11-01 15:26:01 +08:00
parent 6b2a6ce538
commit 52d5761dbb
2 changed files with 37 additions and 14 deletions

View File

@@ -45,7 +45,7 @@ public class ElectricBicyclesServerHandler extends ChannelInboundHandlerAdapter
//获取连接通道唯一标识
ChannelId channelId = ctx.channel().id();
//如果map中不包含此连接就保存连接
ChannelManagerUtil.addChannel(channelId.asShortText(), ctx);
ChannelManagerUtil.addChannel(channelId, ctx);
// if (CHANNEL_MAP.containsKey(channelId)) {
// log.info("客户端【{}】是连接状态,连接通道数量: {}", channelId, CHANNEL_MAP.size());
// } else {
@@ -90,7 +90,7 @@ public class ElectricBicyclesServerHandler extends ChannelInboundHandlerAdapter
String clientIp = insocket.getAddress().getHostAddress();
ChannelId channelId = ctx.channel().id();
//包含此客户端才去删除
ChannelManagerUtil.removeChannel(channelId.asShortText());
ChannelManagerUtil.removeChannel(channelId);
// if (CHANNEL_MAP.containsKey(channelId)) {
// ykcService.exit(channelId);
// //删除连接