From 82954841147ed6e258fefcff926697885ef65d7b Mon Sep 17 00:00:00 2001
From: endian11 <Dana_Lee1016@126.com>
Date: 星期五, 13 十二月 2019 14:28:11 +0800
Subject: [PATCH] 目前可以走通连接,和发送数据;需要关注ByteBuf是否需要手动释放,什么时候释放; 修改了google json array解析数据

---
 im_lib/src/main/java/com/anyun/im_lib/netty/TCPReadHandler.java |   18 ++++++++++++++++--
 1 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/im_lib/src/main/java/com/anyun/im_lib/netty/TCPReadHandler.java b/im_lib/src/main/java/com/anyun/im_lib/netty/TCPReadHandler.java
index 768ca32..2a7fe43 100644
--- a/im_lib/src/main/java/com/anyun/im_lib/netty/TCPReadHandler.java
+++ b/im_lib/src/main/java/com/anyun/im_lib/netty/TCPReadHandler.java
@@ -3,7 +3,12 @@
 import android.util.Log;
 
 import com.anyun.im_lib.interf.IMSClientInteface;
+import com.anyun.im_lib.util.ByteUtil;
 
+import java.nio.ByteBuffer;
+import java.nio.charset.Charset;
+
+import io.netty.buffer.ByteBuf;
 import io.netty.channel.Channel;
 import io.netty.channel.ChannelHandlerContext;
 import io.netty.channel.ChannelInboundHandlerAdapter;
@@ -45,6 +50,7 @@
         Channel channel = ctx.channel();
         if (channel != null){
             channel.close();
+            ctx.close();
         }
         //瑙﹀彂閲嶈繛
         imsClient.resetConnect(false);
@@ -54,13 +60,21 @@
     public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
         super.channelRead(ctx, msg);
         // TODO: 2019/12/4
-        Log.i(TAG, "channelRead: ");
-        imsClient.getMsgDispatcher().receivedMsg((String)msg);
+        //鏈嶅姟绔繑鍥炴秷鎭悗
+        ByteBuf buf = (ByteBuf) msg;
+        byte[] req = new byte[buf.readableBytes()];
+        buf.readBytes(req);
+        String str = new String(req, "UTF-8");
+        System.out.println("鏈嶅姟绔暟鎹负 :" + str);
+
+        Log.i(TAG, "channelRead: "+     str);
+        imsClient.getMsgDispatcher().receivedMsg(   str  );
     }
 
     @Override
     public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
         super.channelReadComplete(ctx);
         Log.i(TAG, "channelReadComplete");
+
     }
 }

--
Gitblit v1.8.0