Files
godot-docs-l10n/classes/zh_Hant/class_websocketmultiplayerpeer.rst

250 lines
14 KiB
ReStructuredText

:github_url: hide
.. _class_WebSocketMultiplayerPeer:
WebSocketMultiplayerPeer
========================
**繼承:** :ref:`MultiplayerPeer<class_MultiplayerPeer>` **<** :ref:`PacketPeer<class_PacketPeer>` **<** :ref:`RefCounted<class_RefCounted>` **<** :ref:`Object<class_Object>`
WebSocket 伺服器和使用者端的基底類別。
.. rst-class:: classref-introduction-group
說明
----
用於 WebSocket 伺服器和使用者端的基底類別,可以用作 :ref:`MultiplayerAPI<class_MultiplayerAPI>` 的多人對等體。
\ **注意:**\ 匯出到安卓時,在匯出專案或使用一鍵部署之前,請務必在安卓匯出預設中開啟 ``INTERNET`` 許可權。否則,任何型別的網路通信都將被 Android 阻止。
.. rst-class:: classref-reftable-group
屬性
----
.. table::
:widths: auto
+---------------------------------------------------+-------------------------------------------------------------------------------------------+-------------------------+
| :ref:`PackedStringArray<class_PackedStringArray>` | :ref:`handshake_headers<class_WebSocketMultiplayerPeer_property_handshake_headers>` | ``PackedStringArray()`` |
+---------------------------------------------------+-------------------------------------------------------------------------------------------+-------------------------+
| :ref:`float<class_float>` | :ref:`handshake_timeout<class_WebSocketMultiplayerPeer_property_handshake_timeout>` | ``3.0`` |
+---------------------------------------------------+-------------------------------------------------------------------------------------------+-------------------------+
| :ref:`int<class_int>` | :ref:`inbound_buffer_size<class_WebSocketMultiplayerPeer_property_inbound_buffer_size>` | ``65535`` |
+---------------------------------------------------+-------------------------------------------------------------------------------------------+-------------------------+
| :ref:`int<class_int>` | :ref:`max_queued_packets<class_WebSocketMultiplayerPeer_property_max_queued_packets>` | ``4096`` |
+---------------------------------------------------+-------------------------------------------------------------------------------------------+-------------------------+
| :ref:`int<class_int>` | :ref:`outbound_buffer_size<class_WebSocketMultiplayerPeer_property_outbound_buffer_size>` | ``65535`` |
+---------------------------------------------------+-------------------------------------------------------------------------------------------+-------------------------+
| :ref:`PackedStringArray<class_PackedStringArray>` | :ref:`supported_protocols<class_WebSocketMultiplayerPeer_property_supported_protocols>` | ``PackedStringArray()`` |
+---------------------------------------------------+-------------------------------------------------------------------------------------------+-------------------------+
.. rst-class:: classref-reftable-group
方法
----
.. table::
:widths: auto
+-------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Error<enum_@GlobalScope_Error>` | :ref:`create_client<class_WebSocketMultiplayerPeer_method_create_client>`\ (\ url\: :ref:`String<class_String>`, tls_client_options\: :ref:`TLSOptions<class_TLSOptions>` = null\ ) |
+-------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Error<enum_@GlobalScope_Error>` | :ref:`create_server<class_WebSocketMultiplayerPeer_method_create_server>`\ (\ port\: :ref:`int<class_int>`, bind_address\: :ref:`String<class_String>` = "*", tls_server_options\: :ref:`TLSOptions<class_TLSOptions>` = null\ ) |
+-------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`WebSocketPeer<class_WebSocketPeer>` | :ref:`get_peer<class_WebSocketMultiplayerPeer_method_get_peer>`\ (\ peer_id\: :ref:`int<class_int>`\ ) |const| |
+-------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`String<class_String>` | :ref:`get_peer_address<class_WebSocketMultiplayerPeer_method_get_peer_address>`\ (\ id\: :ref:`int<class_int>`\ ) |const| |
+-------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`int<class_int>` | :ref:`get_peer_port<class_WebSocketMultiplayerPeer_method_get_peer_port>`\ (\ id\: :ref:`int<class_int>`\ ) |const| |
+-------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
.. rst-class:: classref-section-separator
----
.. rst-class:: classref-descriptions-group
屬性說明
--------
.. _class_WebSocketMultiplayerPeer_property_handshake_headers:
.. rst-class:: classref-property
:ref:`PackedStringArray<class_PackedStringArray>` **handshake_headers** = ``PackedStringArray()`` :ref:`🔗<class_WebSocketMultiplayerPeer_property_handshake_headers>`
.. rst-class:: classref-property-setget
- |void| **set_handshake_headers**\ (\ value\: :ref:`PackedStringArray<class_PackedStringArray>`\ )
- :ref:`PackedStringArray<class_PackedStringArray>` **get_handshake_headers**\ (\ )
握手過程中要使用的額外標頭。詳見 :ref:`WebSocketPeer.handshake_headers<class_WebSocketPeer_property_handshake_headers>`\ 。
**Note:** The returned array is *copied* and any changes to it will not update the original property value. See :ref:`PackedStringArray<class_PackedStringArray>` for more details.
.. rst-class:: classref-item-separator
----
.. _class_WebSocketMultiplayerPeer_property_handshake_timeout:
.. rst-class:: classref-property
:ref:`float<class_float>` **handshake_timeout** = ``3.0`` :ref:`🔗<class_WebSocketMultiplayerPeer_property_handshake_timeout>`
.. rst-class:: classref-property-setget
- |void| **set_handshake_timeout**\ (\ value\: :ref:`float<class_float>`\ )
- :ref:`float<class_float>` **get_handshake_timeout**\ (\ )
每個對等體在被丟棄之前可以保持在連接狀態的最長時間。
.. rst-class:: classref-item-separator
----
.. _class_WebSocketMultiplayerPeer_property_inbound_buffer_size:
.. rst-class:: classref-property
:ref:`int<class_int>` **inbound_buffer_size** = ``65535`` :ref:`🔗<class_WebSocketMultiplayerPeer_property_inbound_buffer_size>`
.. rst-class:: classref-property-setget
- |void| **set_inbound_buffer_size**\ (\ value\: :ref:`int<class_int>`\ )
- :ref:`int<class_int>` **get_inbound_buffer_size**\ (\ )
已連接對等體的入站緩衝區大小。詳見 :ref:`WebSocketPeer.inbound_buffer_size<class_WebSocketPeer_property_inbound_buffer_size>`\ 。
.. rst-class:: classref-item-separator
----
.. _class_WebSocketMultiplayerPeer_property_max_queued_packets:
.. rst-class:: classref-property
:ref:`int<class_int>` **max_queued_packets** = ``4096`` :ref:`🔗<class_WebSocketMultiplayerPeer_property_max_queued_packets>`
.. rst-class:: classref-property-setget
- |void| **set_max_queued_packets**\ (\ value\: :ref:`int<class_int>`\ )
- :ref:`int<class_int>` **get_max_queued_packets**\ (\ )
已連接對等體的最大排隊封包數量。詳見 :ref:`WebSocketPeer.max_queued_packets<class_WebSocketPeer_property_max_queued_packets>`\ 。
.. rst-class:: classref-item-separator
----
.. _class_WebSocketMultiplayerPeer_property_outbound_buffer_size:
.. rst-class:: classref-property
:ref:`int<class_int>` **outbound_buffer_size** = ``65535`` :ref:`🔗<class_WebSocketMultiplayerPeer_property_outbound_buffer_size>`
.. rst-class:: classref-property-setget
- |void| **set_outbound_buffer_size**\ (\ value\: :ref:`int<class_int>`\ )
- :ref:`int<class_int>` **get_outbound_buffer_size**\ (\ )
已連接對等體的出站緩衝區大小。詳見 :ref:`WebSocketPeer.outbound_buffer_size<class_WebSocketPeer_property_outbound_buffer_size>`\ 。
.. rst-class:: classref-item-separator
----
.. _class_WebSocketMultiplayerPeer_property_supported_protocols:
.. rst-class:: classref-property
:ref:`PackedStringArray<class_PackedStringArray>` **supported_protocols** = ``PackedStringArray()`` :ref:`🔗<class_WebSocketMultiplayerPeer_property_supported_protocols>`
.. rst-class:: classref-property-setget
- |void| **set_supported_protocols**\ (\ value\: :ref:`PackedStringArray<class_PackedStringArray>`\ )
- :ref:`PackedStringArray<class_PackedStringArray>` **get_supported_protocols**\ (\ )
支援的 WebSocket 子協定。詳情見 :ref:`WebSocketPeer.supported_protocols<class_WebSocketPeer_property_supported_protocols>`\ 。
**Note:** The returned array is *copied* and any changes to it will not update the original property value. See :ref:`PackedStringArray<class_PackedStringArray>` for more details.
.. rst-class:: classref-section-separator
----
.. rst-class:: classref-descriptions-group
方法說明
--------
.. _class_WebSocketMultiplayerPeer_method_create_client:
.. rst-class:: classref-method
:ref:`Error<enum_@GlobalScope_Error>` **create_client**\ (\ url\: :ref:`String<class_String>`, tls_client_options\: :ref:`TLSOptions<class_TLSOptions>` = null\ ) :ref:`🔗<class_WebSocketMultiplayerPeer_method_create_client>`
啟動新的多人使用者端,連接至給定的 ``url``\ 。使用 ``wss://`` 協議連接時會校驗主機名稱和 TLS 憑證。傳入 ``tls_client_options`` 可以自訂信任的憑證授權,也可以禁用通用名的驗證。見 :ref:`TLSOptions.client()<class_TLSOptions_method_client>`:ref:`TLSOptions.client_unsafe()<class_TLSOptions_method_client_unsafe>`\ 。
\ **注意:**\ 推薦指定 URL 的方案部分,即 ``url`` 應該以 ``ws://````wss://`` 開頭。
.. rst-class:: classref-item-separator
----
.. _class_WebSocketMultiplayerPeer_method_create_server:
.. rst-class:: classref-method
:ref:`Error<enum_@GlobalScope_Error>` **create_server**\ (\ port\: :ref:`int<class_int>`, bind_address\: :ref:`String<class_String>` = "*", tls_server_options\: :ref:`TLSOptions<class_TLSOptions>` = null\ ) :ref:`🔗<class_WebSocketMultiplayerPeer_method_create_server>`
啟動新的多人伺服器,監聽給定的 ``port``\ 。可以指定 ``bind_address``\ ,也可以提供有效的 ``tls_server_options`` 來使用 TLS。見 :ref:`TLSOptions.server()<class_TLSOptions_method_server>`\ 。
.. rst-class:: classref-item-separator
----
.. _class_WebSocketMultiplayerPeer_method_get_peer:
.. rst-class:: classref-method
:ref:`WebSocketPeer<class_WebSocketPeer>` **get_peer**\ (\ peer_id\: :ref:`int<class_int>`\ ) |const| :ref:`🔗<class_WebSocketMultiplayerPeer_method_get_peer>`
返回與給定 ``peer_id`` 關聯的 :ref:`WebSocketPeer<class_WebSocketPeer>`\ 。
.. rst-class:: classref-item-separator
----
.. _class_WebSocketMultiplayerPeer_method_get_peer_address:
.. rst-class:: classref-method
:ref:`String<class_String>` **get_peer_address**\ (\ id\: :ref:`int<class_int>`\ ) |const| :ref:`🔗<class_WebSocketMultiplayerPeer_method_get_peer_address>`
返回給定對等體的 IP 位址。
.. rst-class:: classref-item-separator
----
.. _class_WebSocketMultiplayerPeer_method_get_peer_port:
.. rst-class:: classref-method
:ref:`int<class_int>` **get_peer_port**\ (\ id\: :ref:`int<class_int>`\ ) |const| :ref:`🔗<class_WebSocketMultiplayerPeer_method_get_peer_port>`
返回給定對等體的遠端埠。
.. |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 (無回傳值。)`