我有一个小的server.jar,它在端口10000上监听GET和END命令。
我的客户代码是:
package communication;
import java.io.*;
import java.net.*;
public class Client {
public static void main(String args[]) throws Exception {
try {
Socket socket = null;
PrintWriter out = null;
BufferedReader in = null;
socket = new Socket("localhost",10000);
System.out.println("SOCKET = " + socket);
System.out.print(socket.getInetAddress() + "\n");
System.out.print(socket.getInputStream() + "\n");
System.out.println(socket.isConnected() + "\n");
out = new PrintWriter(socket.getOutputStream(),true);
in = new BufferedReader(new
InputStreamReader(socket.getInputStream()));
String str = "GET";
out.println(str);
String reponse = in.readLine();
System.out.println(socket.isConnected() + "\n");
for(int i = 0; i < 10; i++){
out.println(str); // envoi d'un message
reponse = in.readLine(); // lecture de la reponse
System.out.println("Forme recue: " + reponse);
}
System.out.println("END"); // message de terminaison
out.println("END") ;
in.close();
out.close();
socket.close();
}
catch(IOException e) {
System.out.println(e.getCause());
}
}
}我知道这个代码有效,因为它运行在我的一台计算机上。但是,我不能让它在另一个上运行。两者上的配置都是:Windows 7 64,JRE 6,Eclipse。
我的server.jar应用程序打开了一个小小的GUI,让我知道通信是否打开,这在计算机上从来就不是这样,它会在readLine()线上卡住。
我试图关闭Windows防火墙,防病毒...没有任何工作。
有人知道这里出了什么问题吗?
谢谢!!