From d1e65a28fc73b543b8f34fe118712573682ff2fc Mon Sep 17 00:00:00 2001
From: vince <757871790@qq.com>
Date: 星期三, 17 一月 2024 02:54:28 +0800
Subject: [PATCH] 优化吴家协议

---
 src/main/java/com/fzzy/protocol/wujia/client/ClientEngine.java |   23 ++++++++++++++---------
 1 files changed, 14 insertions(+), 9 deletions(-)

diff --git a/src/main/java/com/fzzy/protocol/wujia/client/ClientEngine.java b/src/main/java/com/fzzy/protocol/wujia/client/ClientEngine.java
index 3e6b01e..26b6467 100644
--- a/src/main/java/com/fzzy/protocol/wujia/client/ClientEngine.java
+++ b/src/main/java/com/fzzy/protocol/wujia/client/ClientEngine.java
@@ -16,7 +16,7 @@
 import java.util.Map;
 
 /**
- * 閫氳鍗忚
+ * 娓镐粰涓诲簱锛岄�氳鍗忚
  */
 @Slf4j
 public class ClientEngine implements Runnable {
@@ -29,7 +29,7 @@
 
     private String host;
     private int port;
-    private Channel defaultChannel;
+    public static Channel defaultChannel;
 
 
     public ClientEngine(String host, int port) {
@@ -45,6 +45,7 @@
     @Override
     public void run() {
         try {
+
             startClient();
         } catch (Exception e) {
             e.printStackTrace();
@@ -52,7 +53,10 @@
     }
 
     public void startClient() throws Exception {
-
+        if(defaultChannel != null){
+            log.info("-----IP={},杩炴帴瀛樺湪锛岀洿鎺ヤ娇鐢�",host);
+            return;
+        }
         EventLoopGroup group = new OioEventLoopGroup();
         Bootstrap b = new Bootstrap();
         //榛樿闀胯繛鎺�
@@ -82,9 +86,9 @@
             @Override
             public void operationComplete(ChannelFuture arg0) throws Exception {
                 if (channelFuture.isSuccess()) {
-                    log.info("-----IP={},杩炴帴鎴愬姛", host);
+                    log.info("-----IP={},杩炴帴鎴愬姛",host);
                 } else {
-                    log.info("-----IP={},杩炴帴澶辫触锛岃嚜鍔ㄥ叧闂嚎绋�", host);
+                    log.info("-----IP={},杩炴帴澶辫触锛岃嚜鍔ㄥ叧闂嚎绋�",host);
                     channelFuture.cause().printStackTrace();
                     group.shutdownGracefully(); // 鍏抽棴绾跨▼缁�
                 }
@@ -107,11 +111,11 @@
     }
 
 
-    public Channel getChannel() {
+    public static Channel getChannel() {
         return defaultChannel;
     }
 
-    public static void add2ChannelMap(String key, Channel channel) {
+    public  void add2ChannelMap(String key, Channel channel) {
         clientChannelMap.put(key, channel);
     }
 
@@ -121,18 +125,19 @@
      * @param key
      * @return
      */
-    public static Channel getChannel(String key) {
+    public static  Channel getChannel(String key) {
         Channel channel = clientChannelMap.get(key);
         if (null == channel) return null;
         if (channel.isActive()) {
             return channel;
         } else {
             channel.close();
+            defaultChannel = null;
         }
         return null;
     }
 
-    public static InvokeResult send2(String hex, Channel channel) throws InterruptedException {
+    public static InvokeResult send2(String hex,Channel channel) throws InterruptedException {
         if (null == channel) {
             return InvokeResult.SOCKET_NOT_CREATE;
         }

--
Gitblit v1.9.3