我正在编写一个多线程聊天服务器/客户端,我一直在使用 SocketTest V 3 来测试服务器,它似乎工作正常,但是当我写一个新行时,我写的客户端只在控制台中更新,我正在使用我的自己的客户端针对套接字测试,每次写入内容时套接字都会更新,但我的客户端没有
public class clientV2 {
public static final int PORT = 5019;
public static InetAddress host;
public static void main(String[] args) throws IOException {
try {
host = InetAddress.getLocalHost();
Socket socket = new Socket(host, PORT);
Scanner in = new Scanner(System.in);
Scanner inputFromServer = new Scanner(socket.getInputStream());
PrintWriter outputToServer = new PrintWriter(socket.getOutputStream());
while(true) {
if(inputFromServer.hasNext()) {
System.out.println(inputFromServer.nextLine());
}
String input = in.nextLine();
outputToServer.println(input);
outputToServer.flush();
}
} catch (Exception e) {
}
}
}