멀티 쓰레드 채팅 서버/클라이언트를 쓰고 있습니다. 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) {
}
}
}
나는 클라이언트가 무언가를 쓸 때마다 인쇄해야합니다. 어떻게해야합니까? – Martin