嗨,我在Java中处理客户端/服务器作业
我必须连接到给定的服务器并进行一些“对话”,但是我遇到一个问题,即在我写入服务器后,我没有收到任何响应(测试中的超时在代码中的“永不到达”注释之前) )
public void run(PrintStream sysout, String host, int port, String myname) {
OutputStream out = null;
BufferedReader in = null;
for (int i = 0; i < COUNT; i++) {
try{
this.connect(host,port); // same as clientSocket constructor
out = this.clientSocket.getOutputStream();
in = new BufferedReader(new InputStreamReader(this.clientSocket.getInputStream()));
out.write(myname.getBytes());
out.flush();
String income = in.readLine(); // never reaches !!!
sysout.print(income);
sysout.flush();
out.close();
}catch(IOException e){
sysout.println(HelloServer.ERR_MESSAGE);
sysout.flush();
continue;
}
}