I'm trying to do some HTTP manually by opening a TCP socket, send the request and read/print the response message. The content of the response body is well printed , but the main thread never exits and blocks forever.
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");
What am I missing, and how can I fix it ?