| | |
| | | package com.dayu.recharge.net; |
| | | |
| | | import android.app.Activity; |
| | | import android.content.Context; |
| | | import android.net.ConnectivityManager; |
| | | import android.net.NetworkInfo; |
| | | import android.os.Looper; |
| | | import android.text.TextUtils; |
| | | import android.util.Log; |
| | | |
| | |
| | | import com.easysocket.interfaces.conn.SocketActionListener; |
| | | import com.easysocket.utils.HexUtil; |
| | | import com.tencent.bugly.crashreport.CrashReport; |
| | | |
| | | import java.util.logging.Handler; |
| | | |
| | | |
| | | /** |
| | |
| | | public static SocketNet getInstance() { |
| | | if (socketNet == null) { |
| | | socketNet = new SocketNet(); |
| | | if (socketNet.socketActionListener != null) { |
| | | |
| | | } |
| | | } |
| | | |
| | | return socketNet; |
| | | } |
| | | |
| | |
| | | |
| | | try { |
| | | mSender = null; |
| | | myCallBack=null; |
| | | myCallBack = null; |
| | | Log.i("SocketActionListener", "SimpleCallBack收到数据-->" + HexUtil.bytesToHex(data.getBodyBytes())); |
| | | SocketData socketData = new SocketData(); |
| | | socketData.setBodyData(data.getBodyBytes()); |
| | |
| | | callBack.onSocketResponse(socketData); |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | |
| | | public void onError(Exception e) { |
| | | super.onError(e); |
| | | mSender = null; |
| | | myCallBack=null; |
| | | myCallBack = null; |
| | | try { |
| | | if (e instanceof RequestTimeOutException) { |
| | | // 在这里执行需要在主线程中执行的操作 |
| | | callBack.onSocketError(-3, "请求超时,正在重试"); |
| | | //超时后重新连接 |
| | | EasySocket.getInstance().disconnect(true); |
| | | } |
| | | |
| | | } catch (Exception ex) { |
| | | throw new RuntimeException(ex); |
| | | } |
| | | } |
| | | }); |
| | | } else { |
| | | callBack.onSocketError(-2, "与服务器连接断开,请检查网络,或者稍后再试"); |
| | | callBack.onSocketError(-2, "与服务器连接断开,请检查网络稍后再试"); |
| | | MyApplication.myApplication.initEasySocket(false, null); |
| | | } |
| | | } else { |