1
1
/*
2
- * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
29
29
import java .io .IOException ;
30
30
import java .io .InputStreamReader ;
31
31
import java .io .PrintWriter ;
32
+ import java .net .InetAddress ;
33
+ import java .net .InetSocketAddress ;
32
34
import java .net .ServerSocket ;
33
35
import java .net .Socket ;
34
36
import java .util .concurrent .ExecutionException ;
@@ -47,7 +49,6 @@ public class TestFrameworkSocket implements AutoCloseable {
47
49
private static final int SERVER_PORT = Integer .getInteger (SERVER_PORT_PROPERTY , -1 );
48
50
49
51
private static final boolean REPRODUCE = Boolean .getBoolean ("Reproduce" );
50
- private static final String HOSTNAME = null ;
51
52
private static Socket clientSocket = null ;
52
53
private static PrintWriter clientWriter = null ;
53
54
@@ -58,7 +59,8 @@ public class TestFrameworkSocket implements AutoCloseable {
58
59
59
60
public TestFrameworkSocket () {
60
61
try {
61
- serverSocket = new ServerSocket (0 );
62
+ serverSocket = new ServerSocket ();
63
+ serverSocket .bind (new InetSocketAddress (InetAddress .getLoopbackAddress (), 0 ));
62
64
} catch (IOException e ) {
63
65
throw new TestFrameworkException ("Failed to create TestFramework server socket" , e );
64
66
}
@@ -132,7 +134,7 @@ public static void write(String msg, String tag, boolean stdout) {
132
134
try {
133
135
// Keep the client socket open until the test VM terminates (calls closeClientSocket before exiting main()).
134
136
if (clientSocket == null ) {
135
- clientSocket = new Socket (HOSTNAME , SERVER_PORT );
137
+ clientSocket = new Socket (InetAddress . getLoopbackAddress () , SERVER_PORT );
136
138
clientWriter = new PrintWriter (clientSocket .getOutputStream (), true );
137
139
}
138
140
if (stdout ) {
0 commit comments