lizhanwei
2020-03-22 40eb16208b55967ec994c00b4e873db9a1e175d0
im_lib/src/main/java/com/anyun/im_lib/netty/NettyTcpClient.java
@@ -13,6 +13,7 @@
import com.anyun.im_lib.listener.OnEventListener;
import com.anyun.im_lib.util.ByteUtil;
import com.anyun.im_lib.util.MyLog;
import com.anyun.im_lib.util.PlatFormConstant;
import com.safeluck.aykj.utils.BytesUtils;
import java.nio.ByteBuffer;
@@ -183,7 +184,7 @@
        try {
            channel = bootstrap.connect(currentHost,currentPort).sync().channel();
        } catch (Exception e) {
            Log.i(TAG, String.format("连接Server(ip[%s],port[%d]失败)",currentHost,currentPort));
            MyLog.i(PlatFormConstant.TAG, String.format("连接Server(ip[%s],port[%d]失败)",currentHost,currentPort));
            try {
                Thread.sleep(500);
            } catch (InterruptedException ex) {
@@ -210,13 +211,13 @@
        this.connectStatus = connectStateConnecting;
        switch (connectStatus){
            case IMSConfig.CONNECT_STATE_CONNECTING:
                Log.i(TAG, "onConnectStatusCallback: ims连接中...");
                MyLog.i(PlatFormConstant.TAG, "onConnectStatusCallback: ims连接中...");
                if (imsConnectStatusCallback != null){
                    imsConnectStatusCallback.onConnecting();
                }
                break;
            case IMSConfig.CONNECT_STATE_SUCCESSFUL:
                MyLog.i(String.format("onConnectStatusCallback: ims连接成功,host[%s],port[%s]",currentHost,currentPort));
                MyLog.i(PlatFormConstant.TAG,String.format("onConnectStatusCallback: ims连接成功,host[%s],port[%s]",currentHost,currentPort));
                if (imsConnectStatusCallback != null){
                    imsConnectStatusCallback.onConnected();
                }
@@ -232,7 +233,7 @@
                break;
            case IMSConfig.CONNECT_STATE_FAILURE:
                default:
                    MyLog.i( "onConnectStatusCallback: ims连接失败");
                    MyLog.i( PlatFormConstant.TAG," ims连接失败");
                    if (imsConnectStatusCallback != null){
                        imsConnectStatusCallback.onConnectFailed();
                    }
@@ -336,12 +337,12 @@
            return;
        }
        try {
            MyLog.i("PlatformMessage", "sendMsg: "+ BytesUtils.bytesToHexString(msg));
            MyLog.i(PlatFormConstant.TAG, "客户端消息(转义后):"+ BytesUtils.bytesToHexString(msg));
            ByteBuf byteBuf = ByteBufAllocator.DEFAULT.ioBuffer();
            byteBuf.writeBytes(msg);
            channel.writeAndFlush(byteBuf);
        } catch (Exception e) {
            Log.i("PlatformMessage", "发送消息失败,reason="+e.getMessage()+"\t"+msg);
            MyLog.i(PlatFormConstant.TAG, "客户端发送消息失败,reason="+e.getMessage()+"\t"+msg);
        }
    }
@@ -456,7 +457,7 @@
        @Override
        public void run() {
            MyLog.i(TAG, "执行重连任务");
            MyLog.i(PlatFormConstant.TAG, "执行重连任务");
            if (!isFirst){
                onConnectStatusCallback(IMSConfig.CONNECT_STATE_FAILURE);
            }
@@ -536,7 +537,7 @@
                    if(connectStatus != IMSConfig.CONNECT_STATE_CONNECTING){
                        onConnectStatusCallback(IMSConfig.CONNECT_STATE_CONNECTING);
                    }
                    MyLog.i( String.format("正在进行connectServer【%s】的第[%d]连接,当前重连延时时长为[%dms]: ",serverUrl,j,j*getReconnectInterval()));
                    MyLog.i(PlatFormConstant.TAG, String.format("正在进行connectServer【%s】的第[%d]连接,当前重连延时时长为[%dms]: ",serverUrl,j,j*getReconnectInterval()));
                    try {
                        currentPort = Integer.parseInt(address[1]);
                        currentHost = address[0];