日期:2014-05-20 浏览次数:20707 次
package JustForTest;
import java.io.*;
import java.net.*;
public class NetServer {
ServerSocket serverSocket = null;
private Socket socket = null;
Runtime rt = Runtime.getRuntime();
private PrintWriter getWriter(Socket socket) throws IOException {
OutputStream out = socket.getOutputStream();
PrintWriter pw = new PrintWriter(out, true);
return pw;
}
private BufferedReader getReader(Socket socket) throws IOException {
InputStream in = socket.getInputStream();
BufferedReader bf = new BufferedReader(new InputStreamReader(in));
return bf;
}
public void service() throws IOException {
serverSocket = new ServerSocket(7324);
socket = serverSocket.accept();
PrintWriter out = getWriter(socket);
BufferedReader bf = getReader(socket);
out.println("Welcome to you!!!");
String comd = null;
// String str=null;
while ((comd = bf.readLine()) != null) {
System.out.println("Execute : "+comd);
String[] comdArray = { "cmd.exe", "/C", comd };
Process pro = rt.exec(comdArray);
try {
pro.waitFor();
} catch (InterruptedException e) {
}
BufferedReader buff = new BufferedReader(new InputStreamReader(pro.getInputStream()));
String tter = null;
StringBuffer stbu = new StringBuffer();
stbu.append("1、这里只测试多行数据发送\n");
stbu.append("2、所以我就不管你数据来源了\n");
stbu.append("3、具体的数据是否正确你另外测试\n");
stbu.append(">>END<<\n"); //结束符
/*
while ((tter = buff.readLine()) != null) {
stbu.append(tter).append("\n");
System.out.println(tter);