此代碼只運行一次。它用於根據其ipv4地址訪問遠程計算機。如何讓這個運行不止一次?
我想讓它隨時可用並運行多次。我應該添加哪些代碼來執行此操作?
public void run() {
try {
ServerSocket ss = new ServerSocket(6609);
Socket s = ss.accept();
System.out.println("connected");
String string = "";
DataInputStream in = new DataInputStream(s.getInputStream());
DataOutputStream out = new DataOutputStream(s.getOutputStream());
string = in.readUTF();
//System.out.println(string);
ProcessBuilder pp = new ProcessBuilder("cmd.exe" , "/c" , "cd " + string);
Process p = pp.start();
DataInputStream get = new DataInputStream(p.getInputStream());
String str = "";
while((str = get.readLine()) != null) {
out.writeUTF(str);
System.out.println(str);
}
System.out.println("Finish server");
} catch(Exception event) {
JOptionPane.showMessageDialog(null, event);
}
//run();
}
第二次發生了什麼?順便說一句,你有一個空的catch(Exception)塊。 *從不*這樣做。打印出例外情況,也許它會告訴你什麼。 – 2014-09-29 11:47:19
thx。我忘了那個。我用一些代碼測試了它。代碼沒有任何反應。一次運行。但一旦我使用循環。它打破了。如果我使用遞歸,更糟。 – 2014-09-29 11:56:22
「壞了」不是問題描述。 '程序失敗'也不是。 – EJP 2014-09-29 11:57:15