TCP 소켓을 열고 요청을 보내고 응답 메시지를 읽거나 인쇄하여 일부 HTTP를 수동으로 처리하려고합니다. 응답 본문의 내용은 잘 인쇄되어 있지만 주 스레드는 절대 종료되지 않고 영원히 차단됩니다.소켓 스트림에서 읽기가 영원히 차단되는 이유는 무엇입니까?
socket = new Socket(host, port);
PrintWriter writer = new PrintWriter(socket.getOutputStream());
writer.print(request);
writer.flush();
BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
reader.lines().forEach(System.out::println);
// String next_record = null;
// while ((next_record = reader.readLine()) != null)
// System.out.println(next_record);
socket.close();
// System.out.println("Finished");
무엇이 빠졌으며 어떻게 해결할 수 있습니까?
EP는 뭔가 것으로 보이는'Lambdas'가 잘되지 않습니다 ;-) – PeterMmm
@PeterMmm 아니, 문제는 람다와는 아무 상관이 없다, 난 그냥 깨끗하고 읽을 수있는 코드를 유지하려고합니다. – tarrsalah
모르겠다 : p, 그래서 내가 여기 왔어. – tarrsalah