我有2个重要的类(客户端和服务器),我会写在我的文本区域的东西,通过点击发送按钮,我会调用客户端类的有效方法,我将文本发送到我的客户端类,每事情是好的,该文本也将被打印在服务器控制台上,但我不能回应从服务器到客户端的文本,请帮助我谢谢。它不会从服务器返回任何东西!
客户端类:(其中的一部分)
os = new PrintWriter(c.getOutputStream(), true);
is = new BufferedReader(new InputStreamReader(c.getInputStream()));
public static void active() {
String teXt = MainClient.getText();
os.println(teXt);
String line = is.readLine();
System.out.println("Text received: " + line);
os.flush();
is.close();
is.close();
c.close();
服务器类:(其中的一部分)
BufferedReader streamIn = new BufferedReader(new InputStreamReader(client.getInputStream()));
PrintWriter streamOut =new PrintWriter(client.getOutputStream());
boolean done = false;
String line =null;
while (!done) {
line = streamIn.readLine();
if (line.equalsIgnoreCase("bye")) {
done = true;
} else {
System.out.println(line);
streamOut.println(line);
}
}
streamIn.close();
client.close();
server.close();
另外这是多线程的客户机/服务器应用程序。 – Johanna 2010-01-18 08:29:58
Johanna,这是你第三次问这个问题。我建议你谷歌的“EchoClient”或“EchoServer”找到一个工作的例子,围绕它建立你的代码。粘贴一吨代码,然后期望人们为你调试并不能很好地利用任何人的时间。 – Adamski 2010-01-18 09:05:05
非常感谢,问题已解决[:-)] – Johanna 2010-01-18 12:08:53