| | |
| | | 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; |
| | |
| | | Channel channel = ctx.channel(); |
| | | if (channel != null){ |
| | | channel.close(); |
| | | ctx.close(); |
| | | } |
| | | //触发重连 |
| | | imsClient.resetConnect(false); |
| | |
| | | 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"); |
| | | |
| | | } |
| | | } |