szetszwo commented on code in PR #1637:
URL: https://github.com/apache/ratis/pull/1637#discussion_r4277617668


##########
ratis-common/src/main/java/org/apache/ratis/util/NetUtils.java:
##########
@@ -166,6 +166,19 @@ static String address2String(InetSocketAddress address) {
 
   String LOCALHOST = "localhost";
 
+  /** IPv4 wildcard for binding a server to all local interfaces. */
+  String WILDCARD_ADDRESS = "0.0.0.0";
+
+  /**
+   * Creates a socket address for binding a server.
+   * When {@code host} is null or empty, uses {@link #WILDCARD_ADDRESS} 
instead of
+   * {@code new InetSocketAddress(port)}, which may resolve to an IPv6 
wildcard.
+   */
+  static InetSocketAddress createBindSocketAddress(String host, int port) {
+    return host == null || host.isEmpty() ?
+        createSocketAddrForHost(WILDCARD_ADDRESS, port) : 
createSocketAddrForHost(host, port);

Review Comment:
   @amaliujia , some questions/comments: 
   - 
   - Could we use JVM option `-Djava.net.preferIPv4Stack=true` ?
   
   - Some systems may support IPv6 only.  Then, this may not work.
   
   - I suggest to try-catch the binding methods such as 
ServerBuilder.forPort(port).  When it fails, fall back to IPv4 wildcard.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to