How do I recognize EOF in Java Sockets?
问题 I want to recognize end of data stream in Java Sockets. When I run the code below, it just stuck and keeps running (it stucks at value 10 ). I also want the program to download binary files, but the last byte is always distinct, so I don't know how to stop the while (pragmatically). String host = "example.com"; String path = "/"; Socket connection = new Socket(host, 80); PrintWriter out = new PrintWriter(connection.getOutputStream()); out.write("GET "+ path +" HTTP/1.1\r\nHost: "+ host +"\r\n