| | |
| | | import com.zy.core.enums.SlaveType; |
| | | import com.zy.core.thread.ShuttleThread; |
| | | import com.zy.core.utils.FakeDeviceUtils; |
| | | import com.zy.core.utils.TimeoutExecutor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | |
| | | import java.io.*; |
| | |
| | | import java.net.SocketTimeoutException; |
| | | import java.text.MessageFormat; |
| | | import java.util.*; |
| | | import java.util.concurrent.TimeUnit; |
| | | |
| | | @Slf4j |
| | | @SuppressWarnings("all") |
| | |
| | | |
| | | try { |
| | | this.connect(); |
| | | // 在循环中使用 |
| | | boolean result = TimeoutExecutor.executeWithTimeout( |
| | | () -> this.listenSocketMessage(), |
| | | 30, // 30秒超时 |
| | | TimeUnit.SECONDS |
| | | ); |
| | | Thread.sleep(200); |
| | | listenSocketMessage(); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | private void listenSocketMessage() { |
| | | private boolean listenSocketMessage() { |
| | | StringBuffer sb = new StringBuffer(); |
| | | try { |
| | | if (this.socket == null) { |
| | | return; |
| | | return false; |
| | | } |
| | | |
| | | DeviceMsgUtils deviceMsgUtils = null; |
| | |
| | | } catch (Exception e) { |
| | | } |
| | | if (deviceMsgUtils == null) { |
| | | return; |
| | | return false; |
| | | } |
| | | |
| | | // 获取输入流 |
| | |
| | | }catch (Exception e){} |
| | | |
| | | if(result == null) { |
| | | return; |
| | | return false; |
| | | } |
| | | |
| | | JSONObject header = null; |
| | |
| | | } |
| | | } |
| | | } catch (SocketTimeoutException e) { |
| | | |
| | | return false; |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | closeSocket(); |
| | | return false; |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | public JSONObject parseSocketResult(JSONObject data) { |