hxb
2024-02-22 d451118d4be05f180cfe1f99bc5904f74db8cc3f
HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/socket/TcpSocketBoot.java
@@ -30,19 +30,17 @@
    private final IClient client;
    private IHeartbeat iHeartbeat;
    public void SetHeartbeat(IHeartbeat iHeartbeat) {
        this.iHeartbeat = iHeartbeat;
    public void SetHeartbeat(IHeartbeat iHeartbeat){
        this.iHeartbeat=iHeartbeat;
    }
    /**
     * 当前接收到数据的时间
     */
    private long time = System.currentTimeMillis();
    private  long time=System.currentTimeMillis();
    /**
     * tcp是否已经连接
     */
    private boolean connected = false;
    private boolean connected=false;
    public IClient getClient() {
        return client;
@@ -56,7 +54,7 @@
    private final ArrayMap<String, SendListener> sendMap = new ArrayMap<>();
    public TcpSocketBoot(IClient client) {
    public  TcpSocketBoot(IClient client) {
        TCP_SOCKET_BOOT_LIST.add(this);
        this.client = client;
        initConnectThread();
@@ -68,25 +66,25 @@
    /**
     * 记录所有SocketBoot
     */
    final static List<TcpSocketBoot> TCP_SOCKET_BOOT_LIST = new ArrayList<>();
    final static List<TcpSocketBoot> TCP_SOCKET_BOOT_LIST = new ArrayList();
    /**
     * 根据IP地址及端口获取当前socketBoot
     *
     * @param ipAddress
     * @param port
     * @return
     */
    public static TcpSocketBoot getByEndPoint(String ipAddress, int port) {
        if (ipAddress == null) {
            return null;
    public static TcpSocketBoot getByEndPoint(String ipAddress, int port){
        if(ipAddress==null){
            return  null;
        }
        for (TcpSocketBoot tcpSocketBoot : TCP_SOCKET_BOOT_LIST) {
            if (ipAddress.equals(tcpSocketBoot.getClient().getOptions().getIp()) && tcpSocketBoot.getClient().getOptions().getPort() == port) {
        for(TcpSocketBoot tcpSocketBoot : TCP_SOCKET_BOOT_LIST){
            if(ipAddress.equals(tcpSocketBoot.getClient().getOptions().getIp())&& tcpSocketBoot.getClient().getOptions().getPort()==port)
            {
                return tcpSocketBoot;
            }
        }
        return null;
        return  null;
    }
    /**
@@ -94,14 +92,14 @@
     */
    private synchronized void connect() {
        try {
            LogUtils.i("TCP连接:" + this.getClient().getOptions().getIp());
            LogUtils.i("TCP连接:"+this.getClient().getOptions().getIp());
            client.onConnectStatus(ConnectStatus.CONNECTING);
//            Thread.sleep(700);
            client.connect();
            LogUtils.i("TCP连接成功:" + this.getClient().getOptions().getIp());
            connected = true;
            LogUtils.i("TCP连接成功:"+this.getClient().getOptions().getIp());
            connected=true;
            client.onConnectStatus(ConnectStatus.CONNECTED);
        } catch (Exception e) {
        }catch(Exception e) {
            LogUtils.e(e.getMessage());
        }
    }
@@ -118,7 +116,7 @@
                public void run() {
                    while (true) {
                        try {
                            if (!connected) {
                            if(connected==false){
                                Thread.sleep(100);
                                continue;
                            }
@@ -165,7 +163,7 @@
                            if (connected) {
                                //读取数据
                                client.onHandleResponse();
                                time = System.currentTimeMillis();
                                time= System.currentTimeMillis();
                            } else {
                                try {
                                    Thread.sleep(1000);
@@ -198,7 +196,7 @@
                            if (!connected) {
                                reconect();
                            }
                            Thread.sleep(5 * 1000);
                            Thread.sleep(5*1000);
                        } catch (Exception e) {
                            LogUtils.e("定时连接线程异常:" + e.getMessage());
@@ -236,7 +234,6 @@
            });
        }
    }
    /**
     * 重新连接
     */
@@ -247,7 +244,6 @@
    /**
     * 发送无需回调
     *
     * @param msg 发送的数据
     */
    public void sendMsg(byte[] msg) {
@@ -283,6 +279,7 @@
        }
    }
//    /**
//     * 断开全部的Link网关连接
//     */