| | |
| | | package com.zy.core.thread; |
| | | |
| | | import com.core.common.Cools; |
| | | import com.zy.common.utils.News; |
| | | import com.zy.core.Slave; |
| | | import com.zy.core.ThreadHandler; |
| | | import lombok.Data; |
| | |
| | | |
| | | @Override |
| | | public boolean connect() { |
| | | String methodName = Thread.currentThread().getStackTrace()[1].getMethodName(); |
| | | |
| | | try { |
| | | close(); //1.主动释放连接 //2.某些服务器对指定ip有链路数限制 |
| | | socket = new Socket(); |
| | |
| | | socket.connect(socketAddress, 1000); //某些服务器ping延迟高时要增加,否则会报错connect timeout |
| | | dataOutputStream = new DataOutputStream(socket.getOutputStream()); |
| | | dataInputStream = new DataInputStream(socket.getInputStream()); |
| | | // log.info("条码扫描仪连接成功 ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); |
| | | // News.info("条码扫描仪连接成功 ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); |
| | | } catch (Exception e) { |
| | | socket = null; |
| | | log.error("条码扫描仪连接失败!!! ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); |
| | | News.error(methodName + ":条码扫描仪连接失败!!! ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); |
| | | return false; |
| | | } |
| | | return true; |
| | |
| | | } |
| | | socket = null; |
| | | } catch (IOException e) { |
| | | log.error("SocketClient close Exception:" + e.getMessage()); |
| | | News.error("SocketClient close Exception:" + e.getMessage()); |
| | | } |
| | | } |
| | | |