|
@@ -1,5 +1,6 @@
|
|
|
package com.warewms.thread;
|
|
|
|
|
|
+import com.warewms.common.utils.ByteUtil;
|
|
|
import com.warewms.common.utils.R;
|
|
|
import com.warewms.common.utils.SpringContextUtils;
|
|
|
import com.warewms.form.BtnOpForm;
|
|
@@ -19,6 +20,7 @@ public class ReadClientDataThread implements Runnable {
|
|
|
private InputStream is = null;
|
|
|
private OutputStream os = null;
|
|
|
private String ipHome = null;
|
|
|
+ private Socket socket = null;
|
|
|
|
|
|
public ReadClientDataThread(Socket socket) {
|
|
|
try {
|
|
@@ -26,6 +28,7 @@ public class ReadClientDataThread implements Runnable {
|
|
|
ipHome = address.getHostAddress();
|
|
|
is = socket.getInputStream();
|
|
|
os = socket.getOutputStream();
|
|
|
+ socket = socket;
|
|
|
} catch (IOException e) {
|
|
|
System.out.println("获取已连接会话中的输入流出现了错误:\n");
|
|
|
e.printStackTrace();
|
|
@@ -41,41 +44,65 @@ public class ReadClientDataThread implements Runnable {
|
|
|
WcsTransitionUtils wcsTransitionUtils = new WcsTransitionUtils();
|
|
|
BtnService buttonTaskService = (BtnService) SpringContextUtils.getBean("btnServiceImpl");//注入ben
|
|
|
R r = new R();
|
|
|
-
|
|
|
- while ((len = is.read(bytes)) != -1) {
|
|
|
- log.info("________________");
|
|
|
- log.info("客户端地址:" + ipHome);
|
|
|
- log.info("________________");
|
|
|
+ while (true) {
|
|
|
try {
|
|
|
- //02EACDF2CDF2CBEA0202
|
|
|
- //CBEACDF2CDF2CBEA0202
|
|
|
- //请求参数
|
|
|
- BtnOpForm btnOpForm = new BtnOpForm();
|
|
|
- btnOpForm.setIp(ipHome);
|
|
|
- String orderText = wcsTransitionUtils.bytesToHexString(bytes).replace(" ", "");
|
|
|
- //System.out.println(orderText);
|
|
|
- if (orderText.equals("2A0163030203016D2424")) {
|
|
|
- btnOpForm.setOpType("CLOSE");
|
|
|
- buttonTaskService.opBtn(btnOpForm);
|
|
|
- log.info("控制-------------------》");
|
|
|
- } else if (orderText.equals("2A0163030204016E2424")) {
|
|
|
- btnOpForm.setOpType("OPEN");
|
|
|
- buttonTaskService.opBtn(btnOpForm);
|
|
|
- log.info("解除控制-------------------》");
|
|
|
- } else {
|
|
|
- //log.info("过滤无效的指令");
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("调用接口下达任务出现异常-异常原因如下:");
|
|
|
- log.error(e.getMessage());
|
|
|
+ Thread.sleep(1000);
|
|
|
+ } catch (InterruptedException e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
+ // 服务器向客户端写,如果客户端断开了,这边会抛出异常,释放线程
|
|
|
+ os.write(ByteUtil.hexString2ByteArray("0000000000"));
|
|
|
+ while ((len = is.read(bytes)) != -1) {
|
|
|
+ log.info("________________");
|
|
|
+ log.info("客户端地址:" + ipHome);
|
|
|
+ log.info("________________");
|
|
|
+ try {
|
|
|
+ //02EACDF2CDF2CBEA0202
|
|
|
+ //CBEACDF2CDF2CBEA0202
|
|
|
+ //请求参数
|
|
|
+ BtnOpForm btnOpForm = new BtnOpForm();
|
|
|
+ btnOpForm.setIp(ipHome);
|
|
|
+ String orderText = wcsTransitionUtils.bytesToHexString(bytes).replace(" ", "");
|
|
|
+ //System.out.println(orderText);
|
|
|
+ if (orderText.equals("2A0163030203016D2424")) {
|
|
|
+ btnOpForm.setOpType("CLOSE");
|
|
|
+ buttonTaskService.opBtn(btnOpForm);
|
|
|
+ log.info("控制-------------------》");
|
|
|
+ } else if (orderText.equals("2A0163030204016E2424")) {
|
|
|
+ btnOpForm.setOpType("OPEN");
|
|
|
+ buttonTaskService.opBtn(btnOpForm);
|
|
|
+ log.info("解除控制-------------------》");
|
|
|
+ } else {
|
|
|
+ //log.info("过滤无效的指令");
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("调用接口下达任务出现异常-异常原因如下:");
|
|
|
+ log.error(e.getMessage());
|
|
|
+ e.printStackTrace();
|
|
|
+ } finally {
|
|
|
+ try {
|
|
|
+ is.close();
|
|
|
+ os.close();
|
|
|
+ socket.close();
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
log.error("读取按钮盒信息失败");
|
|
|
log.error(e.getMessage());
|
|
|
// e.printStackTrace();
|
|
|
+ }finally {
|
|
|
+ try {
|
|
|
+ is.close();
|
|
|
+ os.close();
|
|
|
+ socket.close();
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|