import java.net.*; import java.io.*; import java.util.*; class Server implements Runnable { private static final int DEFAULT_PORT = 8778; private ServerSocket mainSock = null; private static Vector conVec = new Vector(7, 2); // connection vector public int this_port = DEFAULT_PORT; Thread runner; /** * constructor */ public Server() { try { mainSock = new ServerSocket(this_port); } catch(Exception e) { System.err.println("Can't create system socket, system exits."); System.exit(1); } } /** * waits for a connection then spawns a ServerManager to deal with it */ public void run() { // continuously listen the socket while (true) { try { Socket this_connection = mainSock.accept(); ServerManager manager = new ServerManager(this_connection, this); manager.start(); conVec.addElement(manager); //clean up the vector if needed for (int i=0; i> execution.script") ; Runtime.getRuntime().exec("cat " + file_tmp + ">> execution.script"); */ /* while (st != null) { pout.println(st) ; st = din.readLine() ; } */ // fin.close() ; fout.close(); } else if(st.equals("run")) { try { Process p = Runtime.getRuntime().exec("./petasim"); DataInputStream dis = new DataInputStream (new BufferedInputStream(p.getInputStream())); String s = null; s = dis.readLine(); //while ((s = dis.readLine()) != null) { out.writeBytes(s); out.writeByte('\n'); System.out.println(s); // } } catch (Exception e){ System.out.println("the detailed msg:" + e); String s = " Error ! Please Check your Inputs."; out.writeBytes(s); out.writeByte('\n'); System.out.println(s); } //out.writeBytes("done"); //out.writeByte('\n'); } else if(st.equals("result")) { DataInputStream din; FileInputStream fin; fin = new FileInputStream("results.out"); din = new DataInputStream(fin); out.writeBytes(din.readLine()); out.writeByte('\n'); out.writeBytes("done result"); out.writeByte('\n'); din.close(); } else if(st.equals("clearResult")) { Process p3 = Runtime.getRuntime().exec ("/usr/bin/cp ./results.out ./results.out11"); Runtime rt = Runtime.getRuntime(); Process p2 = rt.exec ("/usr/bin/cp ./results.clean ./results.out"); } else if(st.equals("example")) { DataInputStream din; FileInputStream fin; String fname, sin; fname = in.readLine(); while(!fname.equals("done")) { //System.out.println("----------: " + fname); //--out.writeBytes(fname); //--out.writeByte('\n'); if (fname.substring(3,fname.length()).equals("exec.scrpt")) { System.out.println("************************* " + fname) ; fout = new FileOutputStream("current.example"); pout = new PrintStream(fout); pout.println(fname); fin = new FileInputStream(fname); din = new DataInputStream(fin); sin = din.readLine(); int line_num = 0; while(sin != null) { out.writeBytes(sin); out.writeByte('\n'); out.writeBytes(" <"); out.writeByte('\n'); sin = din.readLine(); line_num++ ; if (line_num == 40) break; } } else { System.out.println("************************* " + fname) ; fin = new FileInputStream(fname); din = new DataInputStream(fin); sin = din.readLine(); while(sin != null) { //System.out.println("+++++++++: " + sin); out.writeBytes(sin); out.writeByte('\n'); out.writeBytes(" <"); out.writeByte('\n'); sin = din.readLine(); //System.out.println("+++++222: " + sin); } } out.writeBytes("?"); out.writeByte('\n'); out.writeBytes("|"); out.writeByte('\n'); fname = in.readLine(); //System.out.println("-------222: " + fname); } out.writeBytes("done"); out.writeByte('\n'); } } } catch (Exception e) { e.printStackTrace(); } } }