gpt4 book ai didi

java - 当 java.net.preferIPv4Stack=true 时,无法对 IPv6 使用 InetAddress.isReachable(timeout)

转载 作者:行者123 更新时间:2023-11-30 02:10:41 24 4
gpt4 key购买 nike

在Linux中,我默认通过设置java.net.preferIPv4Stack=true来禁用IPv6支持,仅在应用程序中支持IPv4。

但是,我现在想使用 InetAddress.isReachable(timeout) 访问外部 IPv6 IP,但它完全失败,并且仅当我设置 java.net.preferIPv4Stack=false 时才有效。

是否有任何方法可以访问 IPv6 IP,但仍保持 java.net.preferIPv4Stack=true?

谢谢

最佳答案

不,这是不可能的,因为您设置的选项 explicitly disables communication with IPv6 only hosts:

java.net.preferIPv4Stack (default: false)

If IPv6 is available on the operating system the underlying native socket will be, by default, an IPv6 socket which lets applications connect to, and accept connections from, both IPv4 and IPv6 hosts. However, in the case an application would rather use IPv4 only sockets, then this property can be set to true. The implication is that it will not be possible for the application to communicate with IPv6 only hosts.

如果您想确保 IPv4 地址优先于 IPv6 地址,但仍然有 IPv6 可用,那么您很幸运 - 这是默认行为! (如果您出于任何原因想要将其更改为首选 IPv6 地址,可以设置 java.net.preferIPv6Addresses=true。)

关于java - 当 java.net.preferIPv4Stack=true 时,无法对 IPv6 使用 InetAddress.isReachable(timeout),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50188394/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com