Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,32 +21,22 @@
import org.apache.hudi.exception.HoodieException;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.DatagramSocket;
import java.net.InetAddress;

/**
* A utility class for network.
*/
public class NetworkUtils {

public static synchronized String getHostname() {
Socket s = null;
try {
s = new Socket();
try (DatagramSocket s = new DatagramSocket()) {
// see https://stackoverflow.com/questions/9481865/getting-the-ip-address-of-the-current-machine-using-java
// for details.
s.connect(new InetSocketAddress("google.com", 80));
s.connect(InetAddress.getByName("8.8.8.8"), 10002);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's 8.8.8.8 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe google.com is more readable.

return s.getLocalAddress().getHostAddress();
} catch (IOException e) {
throw new HoodieException("Unable to find server port", e);
} finally {
if (null != s) {
try {
s.close();
} catch (IOException e) {
throw new HoodieException("Unable to close server port", e);
}
}
}
}
}