我有一个读取和写入网络套接字的线程。
public void run() {
try {
Socket socket = new Socket("10.0.1.11", 19456);
out = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
String message = "13" + seperator + "0" + seperator + "userdata";
out.write(message);
out.flush();
while (listen) {
String input = "";
for (int letter = in.read(); letter != -1; letter = in.read()) {
System.out.println((char)letter);
input += (char)letter;
}
System.out.println(input);
displayText(input);
}
socket.close();
} catch (UnknownHostException e) {
displayText("Could not connect to server!");
} catch (IOException e) {
displayText("Could not open IO to server!");
}
}
但是,for 循环之后的所有内容都不会执行。for 循环内的 System.out.println 打印出它应该打印的所有字母,但是 for 循环后的 System.out.println 和 displayText 函数永远不会执行(用断点检查)......我错过了什么这里?:S