gpt4 book ai didi

java - 客户端退出聊天程序时无限打印"null"

转载 作者:行者123 更新时间:2023-11-30 08:37:40 27 4
gpt4 key购买 nike

当两个(或更多)客户端连接到服务器时,当我为其中一个客户端按下 logout 时,他成功断开连接。但是,其他客户端会无限地在其文本区域打印 "null",因此它会不停地打印 "null"

  public void run(){
if (socket != null && reader != null) {
try {
String in;
while (keepGoing){
try{
in= reader.readLine();
send(in+"\n");
}
}
}
}
}

注意:这不是错误,而是错误,所以我没有得到任何异常。

最佳答案

做类似下面的事情:

while (messageLoop){
try{
messageInput = reader.readLine();

if(messageInput == null) break;

sendMessage(messageInput+"\n");

}
catch(SocketTimeoutException ste){
Thread.yield();
}
}

关于java - 客户端退出聊天程序时无限打印"null",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37060620/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com