mirror of
https://github.com/godotengine/godot-docs-l10n.git
synced 2026-01-04 10:09:56 +03:00
554 lines
26 KiB
ReStructuredText
554 lines
26 KiB
ReStructuredText
:github_url: hide
|
||
|
||
.. _class_ENetPacketPeer:
|
||
|
||
ENetPacketPeer
|
||
==============
|
||
|
||
**继承:** :ref:`PacketPeer<class_PacketPeer>` **<** :ref:`RefCounted<class_RefCounted>` **<** :ref:`Object<class_Object>`
|
||
|
||
`ENetPeer <http://enet.bespin.org/group__peer.html>`__ 的包装类。
|
||
|
||
.. rst-class:: classref-introduction-group
|
||
|
||
描述
|
||
----
|
||
|
||
表示 :ref:`ENetConnection<class_ENetConnection>` 对等体的 PacketPeer 实现。
|
||
|
||
该类无法被直接实例化,但可以在 :ref:`ENetConnection.service()<class_ENetConnection_method_service>` 期间,或通过 :ref:`ENetConnection.get_peers()<class_ENetConnection_method_get_peers>` 进行检索。
|
||
|
||
\ **注意:**\ 导出到 Android 时,在导出项目或使用一键部署之前,请确保在 Android 导出预设中,启用了 ``INTERNET`` 权限。否则,Android 将阻止任何类型的网络通信。
|
||
|
||
.. rst-class:: classref-introduction-group
|
||
|
||
教程
|
||
----
|
||
|
||
- `ENet 网站上的 API 文档 <http://enet.bespin.org/usergroup0.html>`__
|
||
|
||
.. rst-class:: classref-reftable-group
|
||
|
||
方法
|
||
----
|
||
|
||
.. table::
|
||
:widths: auto
|
||
|
||
+-------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`int<class_int>` | :ref:`get_channels<class_ENetPacketPeer_method_get_channels>`\ (\ ) |const| |
|
||
+-------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`int<class_int>` | :ref:`get_packet_flags<class_ENetPacketPeer_method_get_packet_flags>`\ (\ ) |const| |
|
||
+-------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`String<class_String>` | :ref:`get_remote_address<class_ENetPacketPeer_method_get_remote_address>`\ (\ ) |const| |
|
||
+-------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`int<class_int>` | :ref:`get_remote_port<class_ENetPacketPeer_method_get_remote_port>`\ (\ ) |const| |
|
||
+-------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`PeerState<enum_ENetPacketPeer_PeerState>` | :ref:`get_state<class_ENetPacketPeer_method_get_state>`\ (\ ) |const| |
|
||
+-------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`float<class_float>` | :ref:`get_statistic<class_ENetPacketPeer_method_get_statistic>`\ (\ statistic\: :ref:`PeerStatistic<enum_ENetPacketPeer_PeerStatistic>`\ ) |
|
||
+-------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`bool<class_bool>` | :ref:`is_active<class_ENetPacketPeer_method_is_active>`\ (\ ) |const| |
|
||
+-------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| |void| | :ref:`peer_disconnect<class_ENetPacketPeer_method_peer_disconnect>`\ (\ data\: :ref:`int<class_int>` = 0\ ) |
|
||
+-------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| |void| | :ref:`peer_disconnect_later<class_ENetPacketPeer_method_peer_disconnect_later>`\ (\ data\: :ref:`int<class_int>` = 0\ ) |
|
||
+-------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| |void| | :ref:`peer_disconnect_now<class_ENetPacketPeer_method_peer_disconnect_now>`\ (\ data\: :ref:`int<class_int>` = 0\ ) |
|
||
+-------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| |void| | :ref:`ping<class_ENetPacketPeer_method_ping>`\ (\ ) |
|
||
+-------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| |void| | :ref:`ping_interval<class_ENetPacketPeer_method_ping_interval>`\ (\ ping_interval\: :ref:`int<class_int>`\ ) |
|
||
+-------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| |void| | :ref:`reset<class_ENetPacketPeer_method_reset>`\ (\ ) |
|
||
+-------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`Error<enum_@GlobalScope_Error>` | :ref:`send<class_ENetPacketPeer_method_send>`\ (\ channel\: :ref:`int<class_int>`, packet\: :ref:`PackedByteArray<class_PackedByteArray>`, flags\: :ref:`int<class_int>`\ ) |
|
||
+-------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| |void| | :ref:`set_timeout<class_ENetPacketPeer_method_set_timeout>`\ (\ timeout\: :ref:`int<class_int>`, timeout_min\: :ref:`int<class_int>`, timeout_max\: :ref:`int<class_int>`\ ) |
|
||
+-------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| |void| | :ref:`throttle_configure<class_ENetPacketPeer_method_throttle_configure>`\ (\ interval\: :ref:`int<class_int>`, acceleration\: :ref:`int<class_int>`, deceleration\: :ref:`int<class_int>`\ ) |
|
||
+-------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
|
||
.. rst-class:: classref-section-separator
|
||
|
||
----
|
||
|
||
.. rst-class:: classref-descriptions-group
|
||
|
||
枚举
|
||
----
|
||
|
||
.. _enum_ENetPacketPeer_PeerState:
|
||
|
||
.. rst-class:: classref-enumeration
|
||
|
||
enum **PeerState**: :ref:`🔗<enum_ENetPacketPeer_PeerState>`
|
||
|
||
.. _class_ENetPacketPeer_constant_STATE_DISCONNECTED:
|
||
|
||
.. rst-class:: classref-enumeration-constant
|
||
|
||
:ref:`PeerState<enum_ENetPacketPeer_PeerState>` **STATE_DISCONNECTED** = ``0``
|
||
|
||
该对等体已断开连接。
|
||
|
||
.. _class_ENetPacketPeer_constant_STATE_CONNECTING:
|
||
|
||
.. rst-class:: classref-enumeration-constant
|
||
|
||
:ref:`PeerState<enum_ENetPacketPeer_PeerState>` **STATE_CONNECTING** = ``1``
|
||
|
||
该对等体正在尝试连接。
|
||
|
||
.. _class_ENetPacketPeer_constant_STATE_ACKNOWLEDGING_CONNECT:
|
||
|
||
.. rst-class:: classref-enumeration-constant
|
||
|
||
:ref:`PeerState<enum_ENetPacketPeer_PeerState>` **STATE_ACKNOWLEDGING_CONNECT** = ``2``
|
||
|
||
该对等体已确认连接请求。
|
||
|
||
.. _class_ENetPacketPeer_constant_STATE_CONNECTION_PENDING:
|
||
|
||
.. rst-class:: classref-enumeration-constant
|
||
|
||
:ref:`PeerState<enum_ENetPacketPeer_PeerState>` **STATE_CONNECTION_PENDING** = ``3``
|
||
|
||
该对等体正在连接。
|
||
|
||
.. _class_ENetPacketPeer_constant_STATE_CONNECTION_SUCCEEDED:
|
||
|
||
.. rst-class:: classref-enumeration-constant
|
||
|
||
:ref:`PeerState<enum_ENetPacketPeer_PeerState>` **STATE_CONNECTION_SUCCEEDED** = ``4``
|
||
|
||
该对等体已成功连接,但还没有准备好进行通讯(\ :ref:`STATE_CONNECTED<class_ENetPacketPeer_constant_STATE_CONNECTED>`\ )。
|
||
|
||
.. _class_ENetPacketPeer_constant_STATE_CONNECTED:
|
||
|
||
.. rst-class:: classref-enumeration-constant
|
||
|
||
:ref:`PeerState<enum_ENetPacketPeer_PeerState>` **STATE_CONNECTED** = ``5``
|
||
|
||
该对等体已连接,可以进行通讯。
|
||
|
||
.. _class_ENetPacketPeer_constant_STATE_DISCONNECT_LATER:
|
||
|
||
.. rst-class:: classref-enumeration-constant
|
||
|
||
:ref:`PeerState<enum_ENetPacketPeer_PeerState>` **STATE_DISCONNECT_LATER** = ``6``
|
||
|
||
该对等体在没有更多的外发数据包可以发送后,将预计断开连接。
|
||
|
||
.. _class_ENetPacketPeer_constant_STATE_DISCONNECTING:
|
||
|
||
.. rst-class:: classref-enumeration-constant
|
||
|
||
:ref:`PeerState<enum_ENetPacketPeer_PeerState>` **STATE_DISCONNECTING** = ``7``
|
||
|
||
该对等体正在断开连接。
|
||
|
||
.. _class_ENetPacketPeer_constant_STATE_ACKNOWLEDGING_DISCONNECT:
|
||
|
||
.. rst-class:: classref-enumeration-constant
|
||
|
||
:ref:`PeerState<enum_ENetPacketPeer_PeerState>` **STATE_ACKNOWLEDGING_DISCONNECT** = ``8``
|
||
|
||
该对等体已确认断开请求。
|
||
|
||
.. _class_ENetPacketPeer_constant_STATE_ZOMBIE:
|
||
|
||
.. rst-class:: classref-enumeration-constant
|
||
|
||
:ref:`PeerState<enum_ENetPacketPeer_PeerState>` **STATE_ZOMBIE** = ``9``
|
||
|
||
该对等体已丢失连接,但并未真正断开连接(因为该对等体还没有对断开连接请求进行确认)。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _enum_ENetPacketPeer_PeerStatistic:
|
||
|
||
.. rst-class:: classref-enumeration
|
||
|
||
enum **PeerStatistic**: :ref:`🔗<enum_ENetPacketPeer_PeerStatistic>`
|
||
|
||
.. _class_ENetPacketPeer_constant_PEER_PACKET_LOSS:
|
||
|
||
.. rst-class:: classref-enumeration-constant
|
||
|
||
:ref:`PeerStatistic<enum_ENetPacketPeer_PeerStatistic>` **PEER_PACKET_LOSS** = ``0``
|
||
|
||
可靠数据包的平均丢包率,即与 :ref:`PACKET_LOSS_SCALE<class_ENetPacketPeer_constant_PACKET_LOSS_SCALE>` 的比率。
|
||
|
||
.. _class_ENetPacketPeer_constant_PEER_PACKET_LOSS_VARIANCE:
|
||
|
||
.. rst-class:: classref-enumeration-constant
|
||
|
||
:ref:`PeerStatistic<enum_ENetPacketPeer_PeerStatistic>` **PEER_PACKET_LOSS_VARIANCE** = ``1``
|
||
|
||
丢包方差。
|
||
|
||
.. _class_ENetPacketPeer_constant_PEER_PACKET_LOSS_EPOCH:
|
||
|
||
.. rst-class:: classref-enumeration-constant
|
||
|
||
:ref:`PeerStatistic<enum_ENetPacketPeer_PeerStatistic>` **PEER_PACKET_LOSS_EPOCH** = ``2``
|
||
|
||
丢包统计信息上一次被更新的时间(从连接开始后的毫秒数)。丢包统计信息更新的时间间隔为 10 秒,自上次统计信息更新以来,至少必须有一个数据包被发送。
|
||
|
||
.. _class_ENetPacketPeer_constant_PEER_ROUND_TRIP_TIME:
|
||
|
||
.. rst-class:: classref-enumeration-constant
|
||
|
||
:ref:`PeerStatistic<enum_ENetPacketPeer_PeerStatistic>` **PEER_ROUND_TRIP_TIME** = ``3``
|
||
|
||
可靠数据包的平均往返时间。
|
||
|
||
.. _class_ENetPacketPeer_constant_PEER_ROUND_TRIP_TIME_VARIANCE:
|
||
|
||
.. rst-class:: classref-enumeration-constant
|
||
|
||
:ref:`PeerStatistic<enum_ENetPacketPeer_PeerStatistic>` **PEER_ROUND_TRIP_TIME_VARIANCE** = ``4``
|
||
|
||
平均往返时间方差。
|
||
|
||
.. _class_ENetPacketPeer_constant_PEER_LAST_ROUND_TRIP_TIME:
|
||
|
||
.. rst-class:: classref-enumeration-constant
|
||
|
||
:ref:`PeerStatistic<enum_ENetPacketPeer_PeerStatistic>` **PEER_LAST_ROUND_TRIP_TIME** = ``5``
|
||
|
||
可靠数据包的记录的上次行程时间。
|
||
|
||
.. _class_ENetPacketPeer_constant_PEER_LAST_ROUND_TRIP_TIME_VARIANCE:
|
||
|
||
.. rst-class:: classref-enumeration-constant
|
||
|
||
:ref:`PeerStatistic<enum_ENetPacketPeer_PeerStatistic>` **PEER_LAST_ROUND_TRIP_TIME_VARIANCE** = ``6``
|
||
|
||
记录的上次行程时间方差。
|
||
|
||
.. _class_ENetPacketPeer_constant_PEER_PACKET_THROTTLE:
|
||
|
||
.. rst-class:: classref-enumeration-constant
|
||
|
||
:ref:`PeerStatistic<enum_ENetPacketPeer_PeerStatistic>` **PEER_PACKET_THROTTLE** = ``7``
|
||
|
||
该对等体的当前节流状态。
|
||
|
||
.. _class_ENetPacketPeer_constant_PEER_PACKET_THROTTLE_LIMIT:
|
||
|
||
.. rst-class:: classref-enumeration-constant
|
||
|
||
:ref:`PeerStatistic<enum_ENetPacketPeer_PeerStatistic>` **PEER_PACKET_THROTTLE_LIMIT** = ``8``
|
||
|
||
不应被丢弃的不可靠数据包的最大数量。这个值总是大于或等于 ``1`` 。初始值等于 :ref:`PACKET_THROTTLE_SCALE<class_ENetPacketPeer_constant_PACKET_THROTTLE_SCALE>`\ 。
|
||
|
||
.. _class_ENetPacketPeer_constant_PEER_PACKET_THROTTLE_COUNTER:
|
||
|
||
.. rst-class:: classref-enumeration-constant
|
||
|
||
:ref:`PeerStatistic<enum_ENetPacketPeer_PeerStatistic>` **PEER_PACKET_THROTTLE_COUNTER** = ``9``
|
||
|
||
用于增加数据包节流计数器的内部值。该值被硬编码为 ``7`` 且无法更改。你可能想查看 :ref:`PEER_PACKET_THROTTLE_ACCELERATION<class_ENetPacketPeer_constant_PEER_PACKET_THROTTLE_ACCELERATION>`\ 。
|
||
|
||
.. _class_ENetPacketPeer_constant_PEER_PACKET_THROTTLE_EPOCH:
|
||
|
||
.. rst-class:: classref-enumeration-constant
|
||
|
||
:ref:`PeerStatistic<enum_ENetPacketPeer_PeerStatistic>` **PEER_PACKET_THROTTLE_EPOCH** = ``10``
|
||
|
||
节流统计数据上一次被更新的时间(自连接开始以来的毫秒数)。节流统计更新的时间间隔是 :ref:`PEER_PACKET_THROTTLE_INTERVAL<class_ENetPacketPeer_constant_PEER_PACKET_THROTTLE_INTERVAL>`\ 。
|
||
|
||
.. _class_ENetPacketPeer_constant_PEER_PACKET_THROTTLE_ACCELERATION:
|
||
|
||
.. rst-class:: classref-enumeration-constant
|
||
|
||
:ref:`PeerStatistic<enum_ENetPacketPeer_PeerStatistic>` **PEER_PACKET_THROTTLE_ACCELERATION** = ``11``
|
||
|
||
节流的加速系数。更高的值将使 ENet 更快地适应波动的网络条件,从而导致不可靠的数据包\ *更*\ 频繁地被发送。默认值为 ``2``\ 。
|
||
|
||
.. _class_ENetPacketPeer_constant_PEER_PACKET_THROTTLE_DECELERATION:
|
||
|
||
.. rst-class:: classref-enumeration-constant
|
||
|
||
:ref:`PeerStatistic<enum_ENetPacketPeer_PeerStatistic>` **PEER_PACKET_THROTTLE_DECELERATION** = ``12``
|
||
|
||
节流的减速系数。更高的值将使 ENet 更快地适应波动的网络条件,从而导致不可靠的数据包\ *不会*\ 频繁地被发送。默认值为 ``2``\ 。
|
||
|
||
.. _class_ENetPacketPeer_constant_PEER_PACKET_THROTTLE_INTERVAL:
|
||
|
||
.. rst-class:: classref-enumeration-constant
|
||
|
||
:ref:`PeerStatistic<enum_ENetPacketPeer_PeerStatistic>` **PEER_PACKET_THROTTLE_INTERVAL** = ``13``
|
||
|
||
测量最低平均往返时间的时间间隔,供节流机制使用(单位:毫秒)。默认值为 ``5000``\ 。
|
||
|
||
.. rst-class:: classref-section-separator
|
||
|
||
----
|
||
|
||
.. rst-class:: classref-descriptions-group
|
||
|
||
常量
|
||
----
|
||
|
||
.. _class_ENetPacketPeer_constant_PACKET_LOSS_SCALE:
|
||
|
||
.. rst-class:: classref-constant
|
||
|
||
**PACKET_LOSS_SCALE** = ``65536`` :ref:`🔗<class_ENetPacketPeer_constant_PACKET_LOSS_SCALE>`
|
||
|
||
丢包的参考尺度。请参阅 :ref:`get_statistic()<class_ENetPacketPeer_method_get_statistic>` 和 :ref:`PEER_PACKET_LOSS<class_ENetPacketPeer_constant_PEER_PACKET_LOSS>`\ 。
|
||
|
||
.. _class_ENetPacketPeer_constant_PACKET_THROTTLE_SCALE:
|
||
|
||
.. rst-class:: classref-constant
|
||
|
||
**PACKET_THROTTLE_SCALE** = ``32`` :ref:`🔗<class_ENetPacketPeer_constant_PACKET_THROTTLE_SCALE>`
|
||
|
||
节流配置的参考值。默认值为 ``32``\ 。 请参阅 :ref:`throttle_configure()<class_ENetPacketPeer_method_throttle_configure>`\ 。
|
||
|
||
.. _class_ENetPacketPeer_constant_FLAG_RELIABLE:
|
||
|
||
.. rst-class:: classref-constant
|
||
|
||
**FLAG_RELIABLE** = ``1`` :ref:`🔗<class_ENetPacketPeer_constant_FLAG_RELIABLE>`
|
||
|
||
将要发送的数据包标记为可靠。
|
||
|
||
.. _class_ENetPacketPeer_constant_FLAG_UNSEQUENCED:
|
||
|
||
.. rst-class:: classref-constant
|
||
|
||
**FLAG_UNSEQUENCED** = ``2`` :ref:`🔗<class_ENetPacketPeer_constant_FLAG_UNSEQUENCED>`
|
||
|
||
将要发送的数据包标记为无序(不可靠)。
|
||
|
||
.. _class_ENetPacketPeer_constant_FLAG_UNRELIABLE_FRAGMENT:
|
||
|
||
.. rst-class:: classref-constant
|
||
|
||
**FLAG_UNRELIABLE_FRAGMENT** = ``8`` :ref:`🔗<class_ENetPacketPeer_constant_FLAG_UNRELIABLE_FRAGMENT>`
|
||
|
||
将要发送的数据包标记为不可靠,即使数据包太大且需要分片(增加其被丢弃的机会)。
|
||
|
||
.. rst-class:: classref-section-separator
|
||
|
||
----
|
||
|
||
.. rst-class:: classref-descriptions-group
|
||
|
||
方法说明
|
||
--------
|
||
|
||
.. _class_ENetPacketPeer_method_get_channels:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`int<class_int>` **get_channels**\ (\ ) |const| :ref:`🔗<class_ENetPacketPeer_method_get_channels>`
|
||
|
||
返回为与对等体通信而分配的通道数。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_ENetPacketPeer_method_get_packet_flags:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`int<class_int>` **get_packet_flags**\ (\ ) |const| :ref:`🔗<class_ENetPacketPeer_method_get_packet_flags>`
|
||
|
||
返回接收队列中下一个数据包的 ENet 标志。可用的数据包标志见 ``FLAG_*`` 常量。请注意,并非所有标志都会从发送端复制到接收端。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_ENetPacketPeer_method_get_remote_address:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`String<class_String>` **get_remote_address**\ (\ ) |const| :ref:`🔗<class_ENetPacketPeer_method_get_remote_address>`
|
||
|
||
返回该对等体的 IP 地址。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_ENetPacketPeer_method_get_remote_port:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`int<class_int>` **get_remote_port**\ (\ ) |const| :ref:`🔗<class_ENetPacketPeer_method_get_remote_port>`
|
||
|
||
返回该对等体的远程端口。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_ENetPacketPeer_method_get_state:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`PeerState<enum_ENetPacketPeer_PeerState>` **get_state**\ (\ ) |const| :ref:`🔗<class_ENetPacketPeer_method_get_state>`
|
||
|
||
返回当前的对等体状态。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_ENetPacketPeer_method_get_statistic:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`float<class_float>` **get_statistic**\ (\ statistic\: :ref:`PeerStatistic<enum_ENetPacketPeer_PeerStatistic>`\ ) :ref:`🔗<class_ENetPacketPeer_method_get_statistic>`
|
||
|
||
返回该对等体的统计信息,由 ``statistic`` 指定。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_ENetPacketPeer_method_is_active:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`bool<class_bool>` **is_active**\ (\ ) |const| :ref:`🔗<class_ENetPacketPeer_method_is_active>`
|
||
|
||
如果对等体当前处于活动状态(即关联的 :ref:`ENetConnection<class_ENetConnection>` 仍然有效),则返回 ``true``\ 。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_ENetPacketPeer_method_peer_disconnect:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
|void| **peer_disconnect**\ (\ data\: :ref:`int<class_int>` = 0\ ) :ref:`🔗<class_ENetPacketPeer_method_peer_disconnect>`
|
||
|
||
请求与对等体断开连接。一旦断开连接完成,在 :ref:`ENetConnection.service()<class_ENetConnection_method_service>` 期间,将生成一个 :ref:`ENetConnection.EVENT_DISCONNECT<class_ENetConnection_constant_EVENT_DISCONNECT>`\ 。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_ENetPacketPeer_method_peer_disconnect_later:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
|void| **peer_disconnect_later**\ (\ data\: :ref:`int<class_int>` = 0\ ) :ref:`🔗<class_ENetPacketPeer_method_peer_disconnect_later>`
|
||
|
||
请求与对等体断开连接,但仅在发送完所有队列的传出数据包之后。一旦断开连接完成,在 :ref:`ENetConnection.service()<class_ENetConnection_method_service>` 期间,将生成一个 :ref:`ENetConnection.EVENT_DISCONNECT<class_ENetConnection_constant_EVENT_DISCONNECT>`\ 。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_ENetPacketPeer_method_peer_disconnect_now:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
|void| **peer_disconnect_now**\ (\ data\: :ref:`int<class_int>` = 0\ ) :ref:`🔗<class_ENetPacketPeer_method_peer_disconnect_now>`
|
||
|
||
强制立即断开与对等体的连接。不会生成 :ref:`ENetConnection.EVENT_DISCONNECT<class_ENetConnection_constant_EVENT_DISCONNECT>`\ 。不保证外部对等体会收到断开连接通知,并会在从此函数返回后立即重置。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_ENetPacketPeer_method_ping:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
|void| **ping**\ (\ ) :ref:`🔗<class_ENetPacketPeer_method_ping>`
|
||
|
||
向对等体发送 ping 请求。ENet 会定期自动 ping 所有连接的对等体,但也可以手动调用此函数,确保进行更频繁的 ping 请求。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_ENetPacketPeer_method_ping_interval:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
|void| **ping_interval**\ (\ ping_interval\: :ref:`int<class_int>`\ ) :ref:`🔗<class_ENetPacketPeer_method_ping_interval>`
|
||
|
||
设置向对等体发送 ping 的间隔 ``ping_interval``\ ,单位为毫秒。Ping 既用于监控连接的有效性,也用于在低流量期间动态调整节流,以便在流量高峰期节流具有合理的响应能力。默认的 ping 间隔为 ``500`` 毫秒。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_ENetPacketPeer_method_reset:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
|void| **reset**\ (\ ) :ref:`🔗<class_ENetPacketPeer_method_reset>`
|
||
|
||
强制断开对等体。对等体代表的外部主机不会收到断开连接的通知,并且会在与本地主机的连接上超时。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_ENetPacketPeer_method_send:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`Error<enum_@GlobalScope_Error>` **send**\ (\ channel\: :ref:`int<class_int>`, packet\: :ref:`PackedByteArray<class_PackedByteArray>`, flags\: :ref:`int<class_int>`\ ) :ref:`🔗<class_ENetPacketPeer_method_send>`
|
||
|
||
将数据包 ``packet`` 加入通过通道 ``channel`` 发送的队列。可用的数据包标志见 ``FLAG_*`` 常量。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_ENetPacketPeer_method_set_timeout:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
|void| **set_timeout**\ (\ timeout\: :ref:`int<class_int>`, timeout_min\: :ref:`int<class_int>`, timeout_max\: :ref:`int<class_int>`\ ) :ref:`🔗<class_ENetPacketPeer_method_set_timeout>`
|
||
|
||
设置对等体的超时参数。超时参数控制对等体因无法确认可靠流量而超时的方式和时间。超时值以毫秒表示。
|
||
|
||
\ ``timeout`` 是一个系数,乘以基于平均往返时间的值,将确定可靠数据包的超时限制。当达到该限制时,超时将加倍,如果该限制已达到 ``timeout_min``\ ,则对等体将断开连接。另一方面,\ ``timeout_max`` 参数定义了一个固定的超时时间,在该时间内必须确认所有数据包,否则对等体将被丢弃。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_ENetPacketPeer_method_throttle_configure:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
|void| **throttle_configure**\ (\ interval\: :ref:`int<class_int>`, acceleration\: :ref:`int<class_int>`, deceleration\: :ref:`int<class_int>`\ ) :ref:`🔗<class_ENetPacketPeer_method_throttle_configure>`
|
||
|
||
为对等体配置节流参数。
|
||
|
||
不可靠的数据包会被 ENet 丢弃,以应对与对等体的互联网连接的各种情况。节流表示一个不可靠数据包不应被丢弃并因此由 ENet 将其发送到对等体的概率。通过测量指定 ``interval`` 内可靠数据包往返时间的波动,ENet 将按照 ``acceleration`` 参数中指定的量增加概率,或者按照 ``deceleration`` 参数中指定的量降低概率(两者都是与 :ref:`PACKET_THROTTLE_SCALE<class_ENetPacketPeer_constant_PACKET_THROTTLE_SCALE>` 的比率)。
|
||
|
||
当节流的值为 :ref:`PACKET_THROTTLE_SCALE<class_ENetPacketPeer_constant_PACKET_THROTTLE_SCALE>` 时,ENet 不会丢弃任何不可靠的数据包,因此所有不可靠数据包以 100% 的概率将被发送。
|
||
|
||
当节流的值为 ``0`` 时,ENet 将丢弃所有不可靠的数据包,因此所有不可靠数据包以 0% 的概率将被发送。
|
||
|
||
节流的中间值表示发送不可靠数据包的 0% 到 100% 之间的中间概率。考虑本地和外部主机的带宽限制,以确定节流概率的合理限制,即使在最好的条件下也不应超过该限制。
|
||
|
||
.. |virtual| replace:: :abbr:`virtual (本方法通常需要用户覆盖才能生效。)`
|
||
.. |required| replace:: :abbr:`required (This method is required to be overridden when extending its base class.)`
|
||
.. |const| replace:: :abbr:`const (本方法无副作用,不会修改该实例的任何成员变量。)`
|
||
.. |vararg| replace:: :abbr:`vararg (本方法除了能接受在此处描述的参数外,还能够继续接受任意数量的参数。)`
|
||
.. |constructor| replace:: :abbr:`constructor (本方法用于构造某个类型。)`
|
||
.. |static| replace:: :abbr:`static (调用本方法无需实例,可直接使用类名进行调用。)`
|
||
.. |operator| replace:: :abbr:`operator (本方法描述的是使用本类型作为左操作数的有效运算符。)`
|
||
.. |bitfield| replace:: :abbr:`BitField (这个值是由下列位标志构成位掩码的整数。)`
|
||
.. |void| replace:: :abbr:`void (无返回值。)`
|