📄 gcsendthread.java
字号:
/* * To change this template, choose Tools | Templates * and open the template in the editor. */package documenteditor;import java.io.IOException;import java.io.OutputStream;import java.util.Date;import java.util.logging.Level;import java.util.logging.Logger;/** * * @author Administrator */public class GCSendThread extends Thread{ private MessageQueue SendMessage = null;//发送信息列队 private OutputStream socketOut = null; //向GPRS发送输出流 private StringBuffer ID = null;//终端唯一标识 private boolean runing = true; private String[] Items = null;//所涉及的十六个污染物 private GPRSClientThread gct = null; public GCSendThread(GPRSClientThread gct){ this.gct = gct; this.SendMessage = gct.getSendMessage(); this.socketOut = gct.getSocketOut(); this.ID = gct.getID(); } @Override public void run(){ while(runing){ try { Date nowdate = new Date(); if(ID.toString().equals("00000000000000")){ //取MN号 socketOut.write(Protocol_WR_WDC07A.ReturnGetMN(gct.getST()).getBytes()); sleep(1000); socketOut.write(Protocol_WR_WDC07A.ReturnGetItems(gct.getID().toString(),gct.getST()).getBytes()); sleep(1000); socketOut.write(Protocol_WR_WDC07A.ReturnGetItemsSet(gct.getID().toString(),gct.getST()).getBytes()); }else if(gct.getItems()[0]==null){ //取通道名称 socketOut.write(Protocol_WR_WDC07A.ReturnGetItems(gct.getID().toString(),gct.getST()).getBytes()); }else if(gct.getNowDataTableModel().getColumnCount()<3){//取通道设置 socketOut.write(Protocol_WR_WDC07A.ReturnGetItemsSet(gct.getID().toString(),gct.getST()).getBytes()); } if(SendMessage.size()>0){//发送待发送数据 socketOut.write(SendMessage.DequeueByte()); } if(nowdate.getTime()-gct.getLastTime().getTime()>1000*60*60*2){//超时自动登出 gct.getSocket().close(); gct.setShutdown(true); runing = false; } if(nowdate.getTime()-gct.getLoginTime_().getTime()>1000*60*60*24){//每隔24小时断掉重连 gct.getSocket().close(); gct.setShutdown(true); runing = false; } sleep(15000); } catch (IOException ex) { try { //Logger.getLogger(GCSendThread.class.getName()).log(Level.SEVERE, null, ex); runing = false; gct.getSocket().close(); gct.setShutdown(true); } catch (IOException ex1) { Logger.getLogger(GCSendThread.class.getName()).log(Level.SEVERE, null, ex1); } } catch (InterruptedException ex) { Logger.getLogger(GCSendThread.class.getName()).log(Level.SEVERE, null, ex); } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -