📄 smstaskthread.java
字号:
package com.yuther.sms.server;import java.io.DataInputStream;import java.io.DataOutputStream;import java.io.InputStream;import java.io.OutputStream;import java.net.Socket;import org.apache.log4j.Logger;import com.yuther.sms.business.Hander;import com.yuther.sms.client.Client;/** * 短信任务线程 * @author yuther * 2008/07/26 */public class SmsTaskThread implements Runnable{ static Logger log = Logger.getLogger(SmsTaskThread.class); //传输socket Socket socket = null; public SmsTaskThread(Socket socket){ this.socket = socket; } public void run() { //输入流 InputStream inStream = null; //输出流 OutputStream outStream = null; log.info(Thread.currentThread().getName()+"己启动!"); try{ inStream = socket.getInputStream(); DataInputStream dataInStream = new DataInputStream(inStream); log.info("****************************************"); //发送方电话号码 int phoneNumber_Len = dataInStream.readInt(); //短信内容长度 int content_Len = dataInStream.readInt(); log.info("***发送方电话号码长度:"+phoneNumber_Len); log.info("***短信内容长度:"+content_Len); byte[] phoneNumber_byte = new byte[phoneNumber_Len]; byte[] content_byte = new byte[content_Len]; dataInStream.readFully(phoneNumber_byte); dataInStream.readFully(content_byte); String phoneNumber = new String(phoneNumber_byte,"UTF-8"); String content = new String(content_byte,"UTF-8"); log.info("*** 发信人:" + phoneNumber); log.info("*** 发送内容:" + content); //运行指令 String result = Hander.CommandRun(phoneNumber, content); //将处理结果回送 byte[] result_byte = result.getBytes("UTF-8"); outStream = socket.getOutputStream(); DataOutputStream dataOut = new DataOutputStream(outStream); dataOut.writeInt(result_byte.length); dataOut.write(result_byte); } catch (Exception e) { log.error("处理异常!",e); try { outStream.write(-1); } catch (Exception ex) { log.error("回执异常!",e); } } finally { try { if (inStream != null) { inStream.close(); } if (socket != null) { socket.close(); } } catch (Exception e) { } } } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -