| | |
| | | import com.hdl.sdk.common.exception.HDLLinkException;
|
| | | import com.hdl.sdk.common.utils.IdUtils;
|
| | | import com.hdl.sdk.common.utils.IpUtils;
|
| | | import com.hdl.sdk.common.utils.LogUtils;
|
| | | import com.hdl.sdk.common.utils.SPUtils;
|
| | | import com.hdl.sdk.common.utils.ThreadToolUtils;
|
| | | import com.hdl.sdk.common.utils.gson.GsonConvert;
|
| | |
| | | pipeLine.add(new LinkMessageDecoder());
|
| | | pipeLine.add(new LinkMessageEncoder());
|
| | | options.setHandleMessage(pipeLine);
|
| | | options.setEnabledHeartbeat(false);
|
| | | options.setEnabledHeartbeat(false);//是否开启心跳包发送检测
|
| | | // options.setHeartbeatTimeInterval(10*1000L);
|
| | | // options.setHeartbeatData("TCP");
|
| | | // options.setEnabledHeartbeat(true);//是否开启心跳包发送检测
|
| | | return options;
|
| | | }
|
| | |
|
| | |
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * 通用TCP发送指令 只发一次,不监听回复,不重发
|
| | | *
|
| | | * @param topic 发送数据
|
| | | * @param bodyStr 回复的主题
|
| | | */
|
| | | public void tcpSendMsg(String topic, String bodyStr) {
|
| | | try {
|
| | | if (TextUtils.isEmpty(topic) || TextUtils.isEmpty(bodyStr)) {
|
| | | LogUtils.e("udpSendMsg", "参数不能为空");
|
| | | return;
|
| | | }
|
| | | LinkRequest message = new LinkRequest(topic, bodyStr);
|
| | | getTcp().sendMsg(message.getSendBytes());
|
| | | } catch (Exception e) {
|
| | | LogUtils.e("tcpSendMsg", "发送失败 :"+e.getMessage());
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * 发送指令
|
| | |
| | | @Override
|
| | | public void onMessage(Object msg) {
|
| | | if (msg instanceof LinkResponse) {
|
| | |
|
| | | LogUtils.e("sendMsg onSuccess");
|
| | | if (callBack != null) {
|
| | | callBack.onSuccess(msg.toString());
|
| | | }
|
| | | threadPool.shutdownNow();
|
| | | }
|
| | | LogUtils.e("sendMsg eventListener remove");
|
| | | EventDispatcher.getInstance().remove(eventTag, this);
|
| | | }
|
| | | };
|
| | |
|
| | |
| | | getTcp().sendMsg(data);
|
| | | } else {
|
| | | threadPool.shutdownNow();
|
| | | LogUtils.e("sendMsg eventListener remove");
|
| | | EventDispatcher.getInstance().remove(eventTag, eventListener);
|
| | | ThreadToolUtils.getInstance().runOnUiThread(new Runnable() {
|
| | | @Override
|