| New file | 
 |  |  | 
 |  |  | package com.dy.simRtu202404.tcpClient; | 
 |  |  |  | 
 |  |  | import com.dy.common.util.Callback; | 
 |  |  | import com.dy.simRtu202404.ServerProperties; | 
 |  |  | import com.dy.simRtu202404.tcpClient.upData.UpData; | 
 |  |  | import com.dy.simRtu202404.tcpClient.upData.UpHeartBeat; | 
 |  |  | import org.apache.logging.log4j.LogManager; | 
 |  |  | import org.apache.logging.log4j.Logger; | 
 |  |  | import org.apache.mina.core.session.IoSession; | 
 |  |  |  | 
 |  |  | /** | 
 |  |  |  * @Author: liurunyu | 
 |  |  |  * @Date: 2025/02/26 11:10 | 
 |  |  |  * @Description | 
 |  |  |  */ | 
 |  |  | public class Starter { | 
 |  |  |  | 
 |  |  |     private static final Logger log = LogManager.getLogger(TcpClUnit.class) ; | 
 |  |  |  | 
 |  |  |     private static Starter instance = new Starter() ; | 
 |  |  |  | 
 |  |  |     private static TcpClUnitConfigVo confVo ; | 
 |  |  |  | 
 |  |  |     public static IoSession session ; | 
 |  |  |  | 
 |  |  |     private Starter(){ | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     public static Starter getInstance(TcpClUnitConfigVo confVo){ | 
 |  |  |         Starter.confVo = confVo ; | 
 |  |  |         return instance ; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     public void doStart(){ | 
 |  |  |         new Thread(() -> { | 
 |  |  |             Exception ex ; | 
 |  |  |             while(true){ | 
 |  |  |                 ex = null ; | 
 |  |  |                 try { | 
 |  |  |                     new TcpConnect().createSession( | 
 |  |  |                             ServerProperties.serverIp, | 
 |  |  |                             ServerProperties.serverPort, | 
 |  |  |                             ServerProperties.connectTimeout, | 
 |  |  |                             new TcpHandler(), | 
 |  |  |                             new Callback() { | 
 |  |  |                                 @Override | 
 |  |  |                                 public void call(Object obj) { | 
 |  |  |                                     if (obj == null) { | 
 |  |  |                                         log.error("创建网络会话返回为null"); | 
 |  |  |                                     } else { | 
 |  |  |                                         Starter.session = (IoSession) obj; | 
 |  |  |                                         log.info("成功创建与通信中间件的网络连接"); | 
 |  |  |                                         Worker.getInstance(Starter.session).doWork(); | 
 |  |  |                                     } | 
 |  |  |                                 } | 
 |  |  |                                 @Override | 
 |  |  |                                 public void call(Object... objs) { | 
 |  |  |                                 } | 
 |  |  |                                 @Override | 
 |  |  |                                 public void exception(Exception e) { | 
 |  |  |                                 } | 
 |  |  |                             }); | 
 |  |  |                 }catch (Exception e){ | 
 |  |  |                     ex = e ; | 
 |  |  |                 } | 
 |  |  |                 if(ex == null){ | 
 |  |  |                     break ; | 
 |  |  |                 }else{ | 
 |  |  |                     try{ | 
 |  |  |                         Thread.sleep(100); | 
 |  |  |                     }catch (Exception e){ | 
 |  |  |                     } | 
 |  |  |                 } | 
 |  |  |             } | 
 |  |  |         }).start(); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  | } |