我正在制作java聊天程序
我读取登录服务器,并将其发送到客户端
首先,我在服务器
中进行了测试public synchronized void SendLogLine(String time, String sender, String fontSize, String fontColor, String fontStyle, String msg) {
System.out.println(time + "\t" + sender + "\t" + fontSize + "\t" + fontColor + "\t" + fontStyle + "\t" + msg);
roomSocketWriter.println("Start Sending Log");
roomSocketWriter.println(time);
roomSocketWriter.println(sender);
roomSocketWriter.println(fontSize);
roomSocketWriter.println(fontColor);
roomSocketWriter.println(fontStyle);
roomSocketWriter.println(msg);
roomSocketWriter.println(delimiter);
}
如果我打印信息,服务器的控制台会显示如下
[14-11-01 00:06:00] room 13 black 0 user_exits
但是,如果我在客户端中打印相同的内容,则它没有一些数据。
这是客户代码
String input = roomSocketReader.readLine();
while(!input.equals("end of log")) {
System.out.println(input);
input = roomSocketReader.readLine();
}
这是打印结果
black
0
user_exits
user_entered
delimiter
Start Sending Log
13
black
0
user_entered
delimiter
Start Sending Log
[14-11-01 09:37:26]
room
13
black
0
user_exits
delimiter
如你所见,很多数据都丢失了:( (空行丢失数据)
有谁知道原因和解决方案?
=============================================== ====================================
我找到客户端停止
的位置我试过调试。
在执行客户端的第一行时 - > String input = roomSocketReader.readLine();
调试行通过
public String readLine() throws IOException {
return readLine(false); <- HERE
}
并停在这里!
String readLine(boolean ignoreLF) throws IOException {
StringBuffer s = null;
int startChar;
boolean omitLF = ignoreLF || skipLF;
synchronized (lock) { <- EXACTLY DEBUG LINE DISAPPEARS AT HERE!
ensureOpen();