📄 clientoutput.java~80~
字号:
package Services;
import java.io.*;
import java.net.*;
import Utilities.*;
import Config;
/**
* <p>Title: InHand SMS platform XMLRouter</p>
* <p>Description: InHand 短信服务平台服务路由器</p>
* <p>Copyright: Copyright (c) 2002</p>
* <p>Company: 北京映翰通网络技术有限公司</p>
* @author 韩传俊 shock2000@21cn.com
* @version 1.0
*/
public class ClientOutput extends Engine {
ServiceInfo serviceInfo=null;
BufferedOutputStream out=null;
public ClientOutput(ServiceInfo serviceInfo,OutputStream out) {
super("module:"+serviceInfo.id+".clientoutput");
this.serviceInfo=serviceInfo;
this.out=new BufferedOutputStream(out,4096);
}
public void run(){
String outStr="";
String test="<cmpp_activetest/>\r\n";
byte[] activeTest=test.getBytes();
while(isRunning()){
if (!this.serviceInfo.data.isEmpty()){
outStr=(String)this.serviceInfo.data.pop();
Config.log.log("module["+this.serviceInfo.id+"].output is running!");
//System.out.println("module["+this.serviceInfo.id+"].output is running!");
//if (outStr!=null){
try{
if(this.out!=null && this.serviceInfo.m_socket!=null){
outStr+="\r\n";
out.write(outStr.getBytes());
this.out.flush();
this.serviceInfo.incOutputNumber();
Config.log.log("clent module["+serviceInfo.id+"]","send",outStr);
}else{
shutdown();
}
}catch(Exception e){
//e.printStackTrace();
Config.log.log(e,"while the thread: "+this.toString()+" is writing data from socket!" );
System.out.println("while the thread: "+this.toString()+" is writing data from socket!");
shutdown();
}
//System.out.println("====in"+this.serviceInfo.id+": "+outStr.substring(0,100)+"...");
//if(outStr.startsWith("<cmpp_deliver")){
// System.out.println(this.toString()+": "+Utility.getCutString(outStr));
// Config.log.log(this.toString()+"read:"+outStr.substring(0,100)+"...");
//}
//}
}else{
this.out.write(activeTest);
this.out.flush();
sleep(100);
}
}
//shutdown();
this.serviceInfo.clientInput=null;
this.serviceInfo.clientOutput=null;
}
public void shutdown(){
super.shutdown();
try{
String outStr="";
while (!this.serviceInfo.data.isEmpty()){
outStr=(String)this.serviceInfo.data.pop();
while (!Config.recv_queue.push(outStr))
nap();
}
if (this.serviceInfo.clientInput.isRunning())
this.serviceInfo.clientInput.shutdown();
this.out.close();
this.serviceInfo.m_socket.close();
this.serviceInfo.m_socket=null;
this.serviceInfo.is_connect=false;
this.serviceInfo.clientInput=null;
this.serviceInfo.clientOutput=null;
Config.log.log("clent module["+serviceInfo.id+"].output shutdown ...");
}catch(Exception e){
Config.log.log(e,"while clent module["+serviceInfo.id+"].output shutdown ...");
}
}
public static void main(String[] args) {
//ClientOutput clientOutput1 = new ClientOutput();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -