Attention: Here be dragons
This is the latest
(unstable) version of this documentation, which may document features
not available in or compatible with released stable versions of Godot.
Checking the stable version of the documentation...
IP
继承: Object
网际协议(IP)支持函数,如 DNS 解析。
描述
IP 包含网际协议(IP)的支持函数。TCP/IP 的支持在其他类中(请参阅 StreamPeerTCP 和 TCPServer)。IP 提供 DNS 主机名解析支持,包括阻塞式和线程式。
方法
void |
clear_cache(hostname: String = "") |
void |
erase_resolve_item(id: int) |
get_local_addresses() const |
|
get_local_interfaces() const |
|
get_resolve_item_address(id: int) const |
|
get_resolve_item_addresses(id: int) const |
|
get_resolve_item_status(id: int) const |
|
resolve_hostname(host: String, ip_type: Type = 3) |
|
resolve_hostname_addresses(host: String, ip_type: Type = 3) |
|
resolve_hostname_queue_item(host: String, ip_type: Type = 3) |
枚举
enum ResolverStatus: 🔗
ResolverStatus RESOLVER_STATUS_NONE = 0
DNS 主机名解析器状态:无状态。
ResolverStatus RESOLVER_STATUS_WAITING = 1
DNS 主机名解析器状态:正在等待。
ResolverStatus RESOLVER_STATUS_DONE = 2
DNS 主机名解析器状态:完成。
ResolverStatus RESOLVER_STATUS_ERROR = 3
DNS 主机名解析器状态:错误。
enum Type: 🔗
Type TYPE_NONE = 0
地址类型:无。
Type TYPE_IPV4 = 1
地址类型:网际协议版本 4(IPv4)。
Type TYPE_IPV6 = 2
地址类型:网际协议版本 6(IPv6)。
Type TYPE_ANY = 3
地址类型:任意。
常量
RESOLVER_MAX_QUERIES = 256
🔗
允许的最大并发 DNS 解析器查询数量,如果超过,则返回 RESOLVER_INVALID_ID。
RESOLVER_INVALID_ID = -1
🔗
无效的 ID 常量。在超过 RESOLVER_MAX_QUERIES 时返回。
方法说明
void clear_cache(hostname: String = "") 🔗
移除所有 hostname
主机名的缓存引用。如果没有给出 hostname
,所有缓存的 IP 地址将被删除。
void erase_resolve_item(id: int) 🔗
从队列中删除一个给定的项目 id
。这应该被用来在队列完成后释放队列,以便进行更多的查询。
PackedStringArray get_local_addresses() const 🔗
以数组形式返回所有用户的当前 IPv4 和 IPv6 地址。
Array[Dictionary] get_local_interfaces() const 🔗
以数组形式返回所有网络适配器。
每个适配器都是一个以下形式的字典:
{
"index":"1", # 接口索引。
"name":"eth0", # 接口名称。
"friendly":"Ethernet One", # 友好的名字(可能是空的)。
"address":["192.168.1.101"], # 与此接口相关的 IP 地址数组。
}
String get_resolve_item_address(id: int) const 🔗
给定队列 id
,返回排队主机名的 IP 地址。出现错误或解析尚未发生时返回一个空字符串(见 get_resolve_item_status)。
Array get_resolve_item_addresses(id: int) const 🔗
如果发生错误或尚未发生解析,则返回已解析的地址或空数组(请参阅 get_resolve_item_status)。
ResolverStatus get_resolve_item_status(id: int) const 🔗
给定队列 id
,以 ResolverStatus 常量的形式返回排队主机名的状态。
String resolve_hostname(host: String, ip_type: Type = 3) 🔗
在解析时返回一个给定的主机名的 IPv4 或 IPv6 地址(阻塞类型方法)。返回的地址类型取决于作为 ip_type
的 Type 常量。
PackedStringArray resolve_hostname_addresses(host: String, ip_type: Type = 3) 🔗
以阻塞方式解析给定的主机名。地址作为 IPv4 或 IPv6 的 Array 数组返回,具体取决于 ip_type
。
int resolve_hostname_queue_item(host: String, ip_type: Type = 3) 🔗
创建一个队列项目,根据 Type 常量 ip_type
,将主机名解析为 IPv4 或 IPv6 地址。如果成功,则返回队列 ID,否则返回 RESOLVER_INVALID_ID。