Skip to content

Commit e4e4e5f

Browse files
authored
Update SocketHeadRequest.java
1 parent f123e3f commit e4e4e5f

1 file changed

Lines changed: 5 additions & 10 deletions

File tree

net/socket/SocketHeadRequest.java

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@
55
import java.io.InputStreamReader;
66
import java.io.PrintWriter;
77
import java.net.Socket;
8-
import java.net.UnknownHostException;
98

109
public class SocketHeadRequest {
1110

12-
public static void main(String[] args) {
11+
public static void main(String[] args) throws IOException {
1312

1413
var hostname = "webcode.me";
1514
int port = 80;
@@ -26,21 +25,17 @@ public static void main(String[] args) {
2625
writer.println("Connection: close");
2726
writer.println();
2827

29-
try (var reader = new BufferedReader(new InputStreamReader(socket.getInputStream()))) {
28+
try (var reader = new BufferedReader(new InputStreamReader(
29+
socket.getInputStream()))) {
30+
3031
String line;
3132

3233
while ((line = reader.readLine()) != null) {
34+
3335
System.out.println(line);
3436
}
3537
}
3638
}
37-
} catch (UnknownHostException ex) {
38-
39-
System.out.println("Server not found: " + ex.getMessage());
40-
41-
} catch (IOException ex) {
42-
43-
System.out.println("I/O error: " + ex.getMessage());
4439
}
4540
}
4641
}

0 commit comments

Comments
 (0)