class_networkedmultiplayerpeer.rst 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. :github_url: hide
  2. .. Generated automatically by doc/tools/make_rst.py in Godot's source tree.
  3. .. DO NOT EDIT THIS FILE, but the NetworkedMultiplayerPeer.xml source instead.
  4. .. The source is found in doc/classes or modules/<name>/doc_classes.
  5. .. _class_NetworkedMultiplayerPeer:
  6. NetworkedMultiplayerPeer
  7. ========================
  8. **Inherits:** :ref:`PacketPeer<class_PacketPeer>` **<** :ref:`Reference<class_Reference>` **<** :ref:`Object<class_Object>`
  9. **Inherited By:** :ref:`MultiplayerPeerGDNative<class_MultiplayerPeerGDNative>`, :ref:`NetworkedMultiplayerENet<class_NetworkedMultiplayerENet>`, :ref:`WebRTCMultiplayer<class_WebRTCMultiplayer>`, :ref:`WebSocketMultiplayerPeer<class_WebSocketMultiplayerPeer>`
  10. A high-level network interface to simplify multiplayer interactions.
  11. Description
  12. -----------
  13. Manages the connection to network peers. Assigns unique IDs to each client connected to the server. See also :ref:`MultiplayerAPI<class_MultiplayerAPI>`.
  14. **Note:** The high-level multiplayer API protocol is an implementation detail and isn't meant to be used by non-Godot servers. It may change without notice.
  15. Tutorials
  16. ---------
  17. - :doc:`../tutorials/networking/high_level_multiplayer`
  18. - `WebRTC Signaling Demo <https://godotengine.org/asset-library/asset/537>`__
  19. Properties
  20. ----------
  21. +-----------------------------------------------------------------+-----------------------------------------------------------------------------------------------+----------+
  22. | :ref:`bool<class_bool>` | :ref:`refuse_new_connections<class_NetworkedMultiplayerPeer_property_refuse_new_connections>` | ``true`` |
  23. +-----------------------------------------------------------------+-----------------------------------------------------------------------------------------------+----------+
  24. | :ref:`TransferMode<enum_NetworkedMultiplayerPeer_TransferMode>` | :ref:`transfer_mode<class_NetworkedMultiplayerPeer_property_transfer_mode>` | ``0`` |
  25. +-----------------------------------------------------------------+-----------------------------------------------------------------------------------------------+----------+
  26. Methods
  27. -------
  28. +-------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------+
  29. | :ref:`ConnectionStatus<enum_NetworkedMultiplayerPeer_ConnectionStatus>` | :ref:`get_connection_status<class_NetworkedMultiplayerPeer_method_get_connection_status>` **(** **)** |const| |
  30. +-------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------+
  31. | :ref:`int<class_int>` | :ref:`get_packet_peer<class_NetworkedMultiplayerPeer_method_get_packet_peer>` **(** **)** |const| |
  32. +-------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------+
  33. | :ref:`int<class_int>` | :ref:`get_unique_id<class_NetworkedMultiplayerPeer_method_get_unique_id>` **(** **)** |const| |
  34. +-------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------+
  35. | void | :ref:`poll<class_NetworkedMultiplayerPeer_method_poll>` **(** **)** |
  36. +-------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------+
  37. | void | :ref:`set_target_peer<class_NetworkedMultiplayerPeer_method_set_target_peer>` **(** :ref:`int<class_int>` id **)** |
  38. +-------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------+
  39. Signals
  40. -------
  41. .. _class_NetworkedMultiplayerPeer_signal_connection_failed:
  42. - **connection_failed** **(** **)**
  43. Emitted when a connection attempt fails.
  44. ----
  45. .. _class_NetworkedMultiplayerPeer_signal_connection_succeeded:
  46. - **connection_succeeded** **(** **)**
  47. Emitted when a connection attempt succeeds.
  48. ----
  49. .. _class_NetworkedMultiplayerPeer_signal_peer_connected:
  50. - **peer_connected** **(** :ref:`int<class_int>` id **)**
  51. Emitted by the server when a client connects.
  52. ----
  53. .. _class_NetworkedMultiplayerPeer_signal_peer_disconnected:
  54. - **peer_disconnected** **(** :ref:`int<class_int>` id **)**
  55. Emitted by the server when a client disconnects.
  56. ----
  57. .. _class_NetworkedMultiplayerPeer_signal_server_disconnected:
  58. - **server_disconnected** **(** **)**
  59. Emitted by clients when the server disconnects.
  60. Enumerations
  61. ------------
  62. .. _enum_NetworkedMultiplayerPeer_TransferMode:
  63. .. _class_NetworkedMultiplayerPeer_constant_TRANSFER_MODE_UNRELIABLE:
  64. .. _class_NetworkedMultiplayerPeer_constant_TRANSFER_MODE_UNRELIABLE_ORDERED:
  65. .. _class_NetworkedMultiplayerPeer_constant_TRANSFER_MODE_RELIABLE:
  66. enum **TransferMode**:
  67. - **TRANSFER_MODE_UNRELIABLE** = **0** --- Packets are not acknowledged, no resend attempts are made for lost packets. Packets may arrive in any order. Potentially faster than :ref:`TRANSFER_MODE_UNRELIABLE_ORDERED<class_NetworkedMultiplayerPeer_constant_TRANSFER_MODE_UNRELIABLE_ORDERED>`. Use for non-critical data, and always consider whether the order matters.
  68. - **TRANSFER_MODE_UNRELIABLE_ORDERED** = **1** --- Packets are not acknowledged, no resend attempts are made for lost packets. Packets are received in the order they were sent in. Potentially faster than :ref:`TRANSFER_MODE_RELIABLE<class_NetworkedMultiplayerPeer_constant_TRANSFER_MODE_RELIABLE>`. Use for non-critical data or data that would be outdated if received late due to resend attempt(s) anyway, for example movement and positional data.
  69. - **TRANSFER_MODE_RELIABLE** = **2** --- Packets must be received and resend attempts should be made until the packets are acknowledged. Packets must be received in the order they were sent in. Most reliable transfer mode, but potentially the slowest due to the overhead. Use for critical data that must be transmitted and arrive in order, for example an ability being triggered or a chat message. Consider carefully if the information really is critical, and use sparingly.
  70. ----
  71. .. _enum_NetworkedMultiplayerPeer_ConnectionStatus:
  72. .. _class_NetworkedMultiplayerPeer_constant_CONNECTION_DISCONNECTED:
  73. .. _class_NetworkedMultiplayerPeer_constant_CONNECTION_CONNECTING:
  74. .. _class_NetworkedMultiplayerPeer_constant_CONNECTION_CONNECTED:
  75. enum **ConnectionStatus**:
  76. - **CONNECTION_DISCONNECTED** = **0** --- The ongoing connection disconnected.
  77. - **CONNECTION_CONNECTING** = **1** --- A connection attempt is ongoing.
  78. - **CONNECTION_CONNECTED** = **2** --- The connection attempt succeeded.
  79. Constants
  80. ---------
  81. .. _class_NetworkedMultiplayerPeer_constant_TARGET_PEER_BROADCAST:
  82. .. _class_NetworkedMultiplayerPeer_constant_TARGET_PEER_SERVER:
  83. - **TARGET_PEER_BROADCAST** = **0** --- Packets are sent to the server and then redistributed to other peers.
  84. - **TARGET_PEER_SERVER** = **1** --- Packets are sent to the server alone.
  85. Property Descriptions
  86. ---------------------
  87. .. _class_NetworkedMultiplayerPeer_property_refuse_new_connections:
  88. - :ref:`bool<class_bool>` **refuse_new_connections**
  89. +-----------+-----------------------------------+
  90. | *Default* | ``true`` |
  91. +-----------+-----------------------------------+
  92. | *Setter* | set_refuse_new_connections(value) |
  93. +-----------+-----------------------------------+
  94. | *Getter* | is_refusing_new_connections() |
  95. +-----------+-----------------------------------+
  96. If ``true``, this ``NetworkedMultiplayerPeer`` refuses new connections.
  97. ----
  98. .. _class_NetworkedMultiplayerPeer_property_transfer_mode:
  99. - :ref:`TransferMode<enum_NetworkedMultiplayerPeer_TransferMode>` **transfer_mode**
  100. +-----------+--------------------------+
  101. | *Default* | ``0`` |
  102. +-----------+--------------------------+
  103. | *Setter* | set_transfer_mode(value) |
  104. +-----------+--------------------------+
  105. | *Getter* | get_transfer_mode() |
  106. +-----------+--------------------------+
  107. The manner in which to send packets to the ``target_peer``. See :ref:`TransferMode<enum_NetworkedMultiplayerPeer_TransferMode>`.
  108. Method Descriptions
  109. -------------------
  110. .. _class_NetworkedMultiplayerPeer_method_get_connection_status:
  111. - :ref:`ConnectionStatus<enum_NetworkedMultiplayerPeer_ConnectionStatus>` **get_connection_status** **(** **)** |const|
  112. Returns the current state of the connection. See :ref:`ConnectionStatus<enum_NetworkedMultiplayerPeer_ConnectionStatus>`.
  113. ----
  114. .. _class_NetworkedMultiplayerPeer_method_get_packet_peer:
  115. - :ref:`int<class_int>` **get_packet_peer** **(** **)** |const|
  116. Returns the ID of the ``NetworkedMultiplayerPeer`` who sent the most recent packet.
  117. ----
  118. .. _class_NetworkedMultiplayerPeer_method_get_unique_id:
  119. - :ref:`int<class_int>` **get_unique_id** **(** **)** |const|
  120. Returns the ID of this ``NetworkedMultiplayerPeer``.
  121. ----
  122. .. _class_NetworkedMultiplayerPeer_method_poll:
  123. - void **poll** **(** **)**
  124. Waits up to 1 second to receive a new network event.
  125. ----
  126. .. _class_NetworkedMultiplayerPeer_method_set_target_peer:
  127. - void **set_target_peer** **(** :ref:`int<class_int>` id **)**
  128. Sets the peer to which packets will be sent.
  129. The ``id`` can be one of: :ref:`TARGET_PEER_BROADCAST<class_NetworkedMultiplayerPeer_constant_TARGET_PEER_BROADCAST>` to send to all connected peers, :ref:`TARGET_PEER_SERVER<class_NetworkedMultiplayerPeer_constant_TARGET_PEER_SERVER>` to send to the peer acting as server, a valid peer ID to send to that specific peer, a negative peer ID to send to all peers except that one. By default, the target peer is :ref:`TARGET_PEER_BROADCAST<class_NetworkedMultiplayerPeer_constant_TARGET_PEER_BROADCAST>`.
  130. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  131. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  132. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`