📄 serverexecuter.java
字号:
/*
* RIC 2 Server Release. by Harry Otten (c) Copyright 2003 hotten@dds.nl
* Check out http://www.hotten.dds.nl/ric/
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
USA.
*/
import java.net.*; // for Socket, ServerSocket, and InetAddress
import java.io.*; // for IOException and Input/OutputStream
import java.util.Vector;
import java.lang.* ;
public class ServerExecuter {
private boolean testMode;
private boolean state=false;
private Config config;
private String COMMAND_CHECK_CONNECTION;
private String COMMAND_HANGUP_CONNECTION;
private String COMMAND_MAKE_CONNECTION;
public ServerExecuter(Config config) {
this.COMMAND_CHECK_CONNECTION=config.getCheckConnection();
this.COMMAND_HANGUP_CONNECTION=config.getHangupConnection();
this.COMMAND_MAKE_CONNECTION=config.getMakeConnection();
};
public ServerExecuter(Config config,boolean testMode) {
this(config);
this.testMode=testMode;
/* the user wants to know this */
if (testMode) System.out.println("Warning server runs test mode. NO real connections");
}
public boolean make() {
if (!testMode)
return execute(COMMAND_MAKE_CONNECTION);
else state=true;
return true;
};
public boolean hangup() {
if (!testMode)
return execute(COMMAND_HANGUP_CONNECTION);
else state=false;
return true;
};
public boolean check() {
if (!testMode)
return execute(COMMAND_CHECK_CONNECTION);
else return state;
};
private boolean execute(String cmd) {
Process m ;
try {
String S = "" ;
m = Runtime.getRuntime().exec(cmd);
BufferedReader in = new BufferedReader(new InputStreamReader(
m.getInputStream()));
while((S=in.readLine()) != null) {
System.out.println(S) ;
}
// Wait until process terminated
m.waitFor();
///System.out.println("exit waarde : "+m.exitValue()) ;
if (m.exitValue()!=0)
return false;
else return true;
} catch(Exception ex) {
ex.printStackTrace();
System.out.println("Execute failed for: "+ cmd);
return false;
}
};
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -