I am trying to write simple socket code that has the following basic form:
try(BufferedReader request = new BufferedReader(new InputStreamReader(sock.getInputStream()))){
My problem is that the socket is closing, but I don't think it should be. The try-with resource creates a BufferedReader and then automatically closes it when I leave the try block, but for some reason it also closes the entire socket! Therefore, when I get a response code that later uses the same socket, I get an exception. Is there any way to fix this? Or do I just not need to use try-with-resources (which would be less than ideal)?
source share