| | |
| | | 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; |
| | |
| | | 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) { |
| | |
| | | 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(); |
| | | } |
| | |
| | | break; |
| | | case IMSConfig.CONNECT_STATE_FAILURE: |
| | | default: |
| | | MyLog.i( "onConnectStatusCallback: ims连接失败"); |
| | | MyLog.i( PlatFormConstant.TAG," ims连接失败"); |
| | | if (imsConnectStatusCallback != null){ |
| | | imsConnectStatusCallback.onConnectFailed(); |
| | | } |
| | |
| | | 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); |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | @Override |
| | | public void run() { |
| | | MyLog.i(TAG, "执行重连任务"); |
| | | MyLog.i(PlatFormConstant.TAG, "执行重连任务"); |
| | | if (!isFirst){ |
| | | onConnectStatusCallback(IMSConfig.CONNECT_STATE_FAILURE); |
| | | } |
| | |
| | | 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]; |