class_packetpeer.rst 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. :github_url: hide
  2. .. Generated automatically by doc/tools/makerst.py in Godot's source tree.
  3. .. DO NOT EDIT THIS FILE, but the PacketPeer.xml source instead.
  4. .. The source is found in doc/classes or modules/<name>/doc_classes.
  5. .. _class_PacketPeer:
  6. PacketPeer
  7. ==========
  8. **Inherits:** :ref:`Reference<class_Reference>` **<** :ref:`Object<class_Object>`
  9. **Inherited By:** :ref:`NetworkedMultiplayerPeer<class_NetworkedMultiplayerPeer>`, :ref:`PacketPeerGDNative<class_PacketPeerGDNative>`, :ref:`PacketPeerStream<class_PacketPeerStream>`, :ref:`PacketPeerUDP<class_PacketPeerUDP>`, :ref:`WebSocketPeer<class_WebSocketPeer>`
  10. **Category:** Core
  11. Brief Description
  12. -----------------
  13. Abstraction and base class for packet-based protocols.
  14. Properties
  15. ----------
  16. +-------------------------+-------------------------------------------------------------------------------+
  17. | :ref:`bool<class_bool>` | :ref:`allow_object_decoding<class_PacketPeer_property_allow_object_decoding>` |
  18. +-------------------------+-------------------------------------------------------------------------------+
  19. Methods
  20. -------
  21. +-------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  22. | :ref:`int<class_int>` | :ref:`get_available_packet_count<class_PacketPeer_method_get_available_packet_count>` **(** **)** const |
  23. +-------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  24. | :ref:`PoolByteArray<class_PoolByteArray>` | :ref:`get_packet<class_PacketPeer_method_get_packet>` **(** **)** |
  25. +-------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  26. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`get_packet_error<class_PacketPeer_method_get_packet_error>` **(** **)** const |
  27. +-------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  28. | :ref:`Variant<class_Variant>` | :ref:`get_var<class_PacketPeer_method_get_var>` **(** :ref:`bool<class_bool>` allow_objects=false **)** |
  29. +-------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  30. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`put_packet<class_PacketPeer_method_put_packet>` **(** :ref:`PoolByteArray<class_PoolByteArray>` buffer **)** |
  31. +-------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  32. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`put_var<class_PacketPeer_method_put_var>` **(** :ref:`Variant<class_Variant>` var, :ref:`bool<class_bool>` full_objects=false **)** |
  33. +-------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  34. Description
  35. -----------
  36. PacketPeer is an abstraction and base class for packet-based protocols (such as UDP). It provides an API for sending and receiving packets both as raw data or variables. This makes it easy to transfer data over a protocol, without having to encode data as low level bytes or having to worry about network ordering.
  37. Property Descriptions
  38. ---------------------
  39. .. _class_PacketPeer_property_allow_object_decoding:
  40. - :ref:`bool<class_bool>` **allow_object_decoding**
  41. +----------+----------------------------------+
  42. | *Setter* | set_allow_object_decoding(value) |
  43. +----------+----------------------------------+
  44. | *Getter* | is_object_decoding_allowed() |
  45. +----------+----------------------------------+
  46. Deprecated. Use ``get_var`` and ``put_var`` parameters instead.
  47. If ``true`` the PacketPeer will allow encoding and decoding of object via :ref:`get_var<class_PacketPeer_method_get_var>` and :ref:`put_var<class_PacketPeer_method_put_var>`.
  48. **WARNING:** Deserialized object can contain code which gets executed. Do not use this option if the serialized object comes from untrusted sources to avoid potential security threats (remote code execution).
  49. Method Descriptions
  50. -------------------
  51. .. _class_PacketPeer_method_get_available_packet_count:
  52. - :ref:`int<class_int>` **get_available_packet_count** **(** **)** const
  53. Returns the number of packets currently available in the ring-buffer.
  54. ----
  55. .. _class_PacketPeer_method_get_packet:
  56. - :ref:`PoolByteArray<class_PoolByteArray>` **get_packet** **(** **)**
  57. Get a raw packet.
  58. ----
  59. .. _class_PacketPeer_method_get_packet_error:
  60. - :ref:`Error<enum_@GlobalScope_Error>` **get_packet_error** **(** **)** const
  61. Returns the error state of the last packet received (via :ref:`get_packet<class_PacketPeer_method_get_packet>` and :ref:`get_var<class_PacketPeer_method_get_var>`).
  62. ----
  63. .. _class_PacketPeer_method_get_var:
  64. - :ref:`Variant<class_Variant>` **get_var** **(** :ref:`bool<class_bool>` allow_objects=false **)**
  65. Get a Variant. When ``allow_objects`` (or :ref:`allow_object_decoding<class_PacketPeer_property_allow_object_decoding>`) is ``true`` decoding objects is allowed.
  66. **WARNING:** Deserialized object can contain code which gets executed. Do not use this option if the serialized object comes from untrusted sources to avoid potential security threats (remote code execution).
  67. ----
  68. .. _class_PacketPeer_method_put_packet:
  69. - :ref:`Error<enum_@GlobalScope_Error>` **put_packet** **(** :ref:`PoolByteArray<class_PoolByteArray>` buffer **)**
  70. Send a raw packet.
  71. ----
  72. .. _class_PacketPeer_method_put_var:
  73. - :ref:`Error<enum_@GlobalScope_Error>` **put_var** **(** :ref:`Variant<class_Variant>` var, :ref:`bool<class_bool>` full_objects=false **)**
  74. Send a Variant as a packet. When ``full_objects`` (or :ref:`allow_object_decoding<class_PacketPeer_property_allow_object_decoding>`) is ``true`` encoding objects is allowed (and can potentially include code).