⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 userthread.java

📁 农业银行ATM对帐查询系统后台类包的源代码,实现了FTP,数据库管理等等功能
💻 JAVA
字号:
package boco.transmonitor.xmlsocket;//******************************************************************************//:功能://:时间:2002-07//:作者:王建宾//:特殊描述::test:为DEBUG时启用//:程序描述://     服务器数据接收线程的实现//******************************************************************************import java.net.*;import java.io.*;import java.util.*;//***************************************************************************//类名称:监控服务器线程//类功能:实现服务器线程方法//**************************************************************************public class UserThread extends Thread{protected DataOutputStream outStream=null;protected Socket socket=null;XmlServer server=null;String operater="";String clientIp="";static String streamFrom="196.168.1.32";ChineseTransfer A2C = new ChineseTransfer(); //***********************************************************************  //方法名称:构造函数  //方法功能:实现SOCKET连接,并实现数据库连接  //***********************************************************************public UserThread(XmlServer server,Socket socket) throws IOException{      try{            this.socket=socket;            this.server=server;            clientIp=socket.getInetAddress().getHostAddress();            outStream=new DataOutputStream(socket.getOutputStream());      }      catch(Exception ee){            System.out.println("初始化线程出错:"+ee.toString());      }  } //**************************************************************************  //方法名称:线程运行方法  //方法功能:覆盖父类方法,实现线程的运行  //**************************************************************************  public void run()  {        while(true){              try{                Thread.sleep(500);                DataInputStream inStream=new DataInputStream(socket.getInputStream());                int availCount = inStream.available();                if(socket.getInetAddress().getHostAddress().equals(streamFrom)){                      byte[] byt = new byte[availCount];                      inStream.read(byt,0,availCount);                      //:test:System.out.println("发送信息主机:"+clientIp);                      String tmpInData = new String(byt,"ISO8859_1");                      //:test:System.out.println("StringIs:"+tmpInData);                      //数据处理                      //:test:System.out.println("availCount:"+availCount);                      if(availCount >= 156)                      {                        aipsDataDeal doAips = new aipsDataDeal();                        doAips.aipsDataDeal(tmpInData);                      }                    }                    //非数据发送源,关闭退出                    else{                      try{                        socket.close();                        this.stop();                      }                      catch(Exception ee){                        System.out.println("错误"+ee.toString());                      }                    }              }              catch(Exception e)              {                try{                  System.out.println("客户机:"+clientIp+"退出");                  socket.close();                  this.stop();                }                catch(Exception ee){                  System.out.println("错误"+ee.toString());                }          }          try{            socket.close();            this.stop();          }catch(Exception ee){            System.out.println("错误"+ee.toString());          }        }  } //************************************************************************  //方法名称:关闭客户连接  //方法功能:关闭数据库,SOCKET  //************************************************************************  protected void closeConnection() throws IOException  {    try{      socket.close();      this.stop();          }          catch(Exception e){            throw new IOException("退出,关闭连接");          }          stop();  } //*************************************************************************  //方法名称:发送信息  //方法功能:向客户端发送信息  //*************************************************************************  public void sendMessage(String msg) throws IOException  {    try{            outStream.writeUTF(msg);    }    catch(Exception e){      System.out.println("向客户发送数据出错:"+e.toString());    }  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -