| | |
| | | package com.hdl.sdk.connect.socket; |
| | | |
| | | import android.text.TextUtils; |
| | | |
| | | import com.google.gson.Gson; |
| | | import com.google.gson.JsonObject; |
| | | import com.google.gson.reflect.TypeToken; |
| | |
| | | import com.hdl.sdk.common.exception.HDLLinkCode; |
| | | import com.hdl.sdk.common.exception.HDLLinkException; |
| | | import com.hdl.sdk.common.utils.LogUtils; |
| | | import com.hdl.sdk.common.utils.TextUtils; |
| | | import com.hdl.sdk.common.utils.ThreadToolUtils; |
| | | import com.hdl.sdk.connect.HDLLink; |
| | | import com.hdl.sdk.connect.bean.response.AuthenticateResponse; |
| | | import com.hdl.sdk.connect.bean.response.NetworkAccessBroadcastResponse; |
| | | import com.hdl.sdk.connect.callback.BaseCallBack; |
| | |
| | | import com.hdl.sdk.socket.udp.UdpSocketBoot; |
| | | import com.hdl.sdk.socket.udp.UdpSocketOptions; |
| | | |
| | | import java.net.InetSocketAddress; |
| | | import java.util.List; |
| | | import java.util.concurrent.atomic.AtomicBoolean; |
| | | import java.util.concurrent.atomic.AtomicInteger; |
| | |
| | | /** |
| | | * instance |
| | | */ |
| | | private volatile static HDLAuthSocket instance; |
| | | private static final HDLAuthSocket instance=new HDLAuthSocket(); |
| | | |
| | | private HDLAuthSocket() { |
| | | initListenerGatewayEvent(); |
| | |
| | | * |
| | | * @return HDLAuthSocket |
| | | */ |
| | | public static synchronized HDLAuthSocket getInstance() { |
| | | if (instance == null) { |
| | | synchronized (HDLLinkConfig.class) { |
| | | if (instance == null) { |
| | | instance = new HDLAuthSocket(); |
| | | } |
| | | } |
| | | } |
| | | public static HDLAuthSocket getInstance() { |
| | | // if (instance == null) { |
| | | // synchronized (HDLAuthSocket.class) { |
| | | // if (instance == null) { |
| | | // instance = new HDLAuthSocket(); |
| | | // } |
| | | // } |
| | | // } |
| | | return instance; |
| | | } |
| | | |
| | |
| | | * |
| | | * @return 返回当前对象 |
| | | */ |
| | | private UdpSocketBoot getUdpBoot() { |
| | | private synchronized UdpSocketBoot getUdpBoot() { |
| | | try { |
| | | if (udpSocketBoot == null) { |
| | | udpSocketBoot = UdpClient.init(UDP_PORT, getUdpOptions()); |
| | | udpSocketBoot.bind(); |
| | | } |
| | | } catch (Exception e) { |
| | | // return null; |
| | | LogUtils.e("初始化Socket udp异常"+e.getMessage()); |
| | | } |
| | | |
| | | return udpSocketBoot; |
| | |
| | | //2.构建监听Listener |
| | | // authEvent = |
| | | //3.监听网关广播的入网指令 |
| | | EventDispatcher.getInstance().remove(TopicConstant.GATEWAY_AUTH_BROADCAST); |
| | | EventDispatcher.getInstance().register(TopicConstant.GATEWAY_AUTH_BROADCAST, new EventListener() { |
| | | @Override |
| | | public void onMessage(Object msg) { |
| | | LogUtils.i("收到网关认证信息: "); |
| | | NetworkAccessBroadcastResponse bean = getNetworkAccessBroadcastResponse(msg); |
| | | if (bean != null) { |
| | | //移除监听 |
| | |
| | | HdlSocketHelper.sendUdp(getUdpBoot(), ip, UDP_PORT, message, new HdlSocketHelper.HdlSocketListener() { |
| | | @Override |
| | | public void onSucceed(Object msg) { |
| | | |
| | | LogUtils.i("onSucceed msg:" + msg); |
| | | |
| | | if (callBack == null) return; |
| | | try { |
| | | AuthenticateResponse bean = getAuthenticateResponseBean(msg); |
| | |
| | | } |
| | | } |
| | | }); |
| | | LogUtils.i("callBackSearchGatewayTimeout onError:搜索网关失败,超时"); |
| | | |
| | | } |
| | | |
| | | |