hxb
2022-03-27 cc6023291bc94a229b53d7c2d83bf2b39bbfa9a0
HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/socket/HDLAuthSocket.java
@@ -68,7 +68,7 @@
    /**
     * instance
     */
    private volatile static HDLAuthSocket instance;
    private  static final HDLAuthSocket instance=new HDLAuthSocket();
    private HDLAuthSocket() {
        initListenerGatewayEvent();
@@ -84,14 +84,14 @@
     *
     * @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;
    }
@@ -110,7 +110,7 @@
     *
     * @return 返回当前对象
     */
    private UdpSocketBoot getUdpBoot() {
    private synchronized UdpSocketBoot getUdpBoot() {
        try {
            if (udpSocketBoot == null) {
                udpSocketBoot = UdpClient.init(UDP_PORT, getUdpOptions());
@@ -408,11 +408,11 @@
     */
    public void udpSendMsg(String topic, String bodyStr,boolean broadcast) {
        if (TextUtils.isEmpty(topic) || TextUtils.isEmpty(bodyStr)) {
            LogUtils.e("udpSendMsg", "参数不能为空");
            LogUtils.e( "参数不能为空,不能发送UDP数据");
            return;
        }
        if (!HDLLinkConfig.getInstance().checkIfCertified()) {
            LogUtils.e("udpSendMsg", "未认证,请先认证");
            LogUtils.e("未认证,请先认证再调用UDP发送方法");
            return;
        }
        LinkRequest message = new LinkRequest(topic, bodyStr);
@@ -492,7 +492,8 @@
                            }.getType());
                            GatewaySearchBean searchBean = response.getObjects();
                            if (searchBean != null && !TextUtils.isEmpty(searchBean.getGatewayId())) {
                                if (searchBean.getGatewayId().contains(searchGatewayId)) {
                                searchBean.setIp_address(linkResponse.getSource_ipAddress());
                                if (searchBean.getGatewayId().contains(searchGatewayId)&&!TextUtils.isEmpty(searchGatewayId)) {
                                    removeSearchGatewayEvent();//移除搜索网关监听
                                    isSearchGatewaySuccess.set(true);//搜索成功标记
                                    searchGatewayCount.set(11);//次数标记
@@ -526,10 +527,14 @@
                            }.getType());
                            GatewaySearchBean gateway = response.getObjects();
                            if (gateway != null && !TextUtils.isEmpty(gateway.getGatewayId())) {
                                //可能网关带过来的ip不对
                                gateway.setIp_address(linkResponse.getSource_ipAddress());
                                //主网关并且是当前绑定的网关
                                if ("true".equals(gateway.getMaster().toLowerCase()) && gateway.getGatewayId().equals(HDLLinkConfig.getInstance().getGatewayId())) {
                                    HDLLinkConfig.getInstance().setCurrentGateway(gateway);//设置当前网关
                                    HDLLinkConfig.getInstance().setIpAddress(gateway.getIp_address());
                                    if(!TextUtils.isEmpty( gateway.getIp_address())) {
                                        HDLLinkConfig.getInstance().setIpAddress(gateway.getIp_address());
                                    }
                                    //更新当前网关的信息
                                    HDLLinkConfig.getInstance().reSaveConfig();
                                }
@@ -582,9 +587,11 @@
                }
                if (!isSearchGatewaySuccess.get()) {
                    //搜索10次,指定网关都没回复,回调超时
                    callBackSearchGatewayTimeout();
                    LogUtils.e("搜索网关", "搜索10次,指定网关都没回复,回调超时");
                    try {
                        LogUtils.e("搜索网关", "搜索10次,指定网关都没回复,回调超时");
                        //搜索10次,指定网关都没回复,回调超时
                        callBackSearchGatewayTimeout();
                    }catch (Exception e){}
                }
            }
        }).start();