感谢您之前的所有回复,非常有帮助。 我有另一个Q服务器/客户端应用程序。我gt服务器/客户端之间的连接。 但现在当我输入内容时,没有任何反应。我实现的run()侦听输入并显示它们。看来这种方法不起作用(这就是为什么没有输出我猜)
这是run()(收到监听和显示消息)和send()(发送消息)
谢谢
public void run(){//watch for incoming communication
String msg;
try{//loop reading lines from the client and display msg
while ((msg = serverIn.readLine()) != null) {
System.out.println("msg received"+msg);
}
}catch (IOException e) {
System.err.println(e);
}
}
public void send(String msg){//send outgoing message
System.out.println("in the send()");
serverOut.println(msg);
}
一些可能有用的信息: 那些方法是在我通过
调用它们的类someClass.start() (someClass extends Thread class)
someClass.send()
答案 0 :(得分:1)
看起来你需要刷新输出流。
public void send(String msg){//send outgoing message
System.out.println("in the send()");
serverOut.println(msg);
serverOut.flush();
}
这假设serverOut
是PrintWriter
似乎是什么?