From 2bc498f07a80ac99b4fa2d68f826661924b1bdb6 Mon Sep 17 00:00:00 2001 From: nico Date: Sun, 6 Jan 2019 23:18:25 +0800 Subject: [PATCH] fix #27 --- .../org/nico/ratel/landlords/server/ServerContains.java | 3 +++ .../ratel/landlords/server/handler/TransferHandler.java | 9 ++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/landlords-server/src/main/java/org/nico/ratel/landlords/server/ServerContains.java b/landlords-server/src/main/java/org/nico/ratel/landlords/server/ServerContains.java index 362e039..5a541c8 100644 --- a/landlords-server/src/main/java/org/nico/ratel/landlords/server/ServerContains.java +++ b/landlords-server/src/main/java/org/nico/ratel/landlords/server/ServerContains.java @@ -2,6 +2,7 @@ package org.nico.ratel.landlords.server; import java.util.Map; import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentSkipListMap; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.ThreadPoolExecutor; @@ -28,6 +29,8 @@ public class ServerContains { */ public final static Map CLIENT_SIDE_MAP = new ConcurrentSkipListMap<>(); + public final static Map CHANNEL_ID_MAP = new ConcurrentHashMap<>(); + private final static AtomicInteger CLIENT_ATOMIC_ID = new AtomicInteger(1); private final static AtomicInteger SERVER_ATOMIC_ID = new AtomicInteger(1); diff --git a/landlords-server/src/main/java/org/nico/ratel/landlords/server/handler/TransferHandler.java b/landlords-server/src/main/java/org/nico/ratel/landlords/server/handler/TransferHandler.java index f227d7d..cb25ab5 100644 --- a/landlords-server/src/main/java/org/nico/ratel/landlords/server/handler/TransferHandler.java +++ b/landlords-server/src/main/java/org/nico/ratel/landlords/server/handler/TransferHandler.java @@ -78,7 +78,13 @@ public class TransferHandler extends ChannelInboundHandlerAdapter{ } private int getId(Channel channel){ - return ((InetSocketAddress)channel.remoteAddress()).getPort(); + String longId = channel.id().asLongText(); + Integer clientId = ServerContains.CHANNEL_ID_MAP.get(longId); + if(null == clientId){ + clientId = ServerContains.getClientId(); + ServerContains.CHANNEL_ID_MAP.put(longId, clientId); + } + return clientId; } private void clientOfflineEvent(Channel channel){ @@ -89,4 +95,5 @@ public class TransferHandler extends ChannelInboundHandlerAdapter{ ServerEventListener.get(ServerEventCode.CODE_CLIENT_OFFLINE).call(client, null); } } + }