class_packetpeer.rst 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. .. Generated automatically by doc/tools/makerst.py in Godot's source tree.
  2. .. DO NOT EDIT THIS FILE, but the PacketPeer.xml source instead.
  3. .. The source is found in doc/classes or modules/<name>/doc_classes.
  4. .. _class_PacketPeer:
  5. PacketPeer
  6. ==========
  7. **Inherits:** :ref:`Reference<class_Reference>` **<** :ref:`Object<class_Object>`
  8. **Inherited By:** :ref:`NetworkedMultiplayerPeer<class_NetworkedMultiplayerPeer>`, :ref:`PacketPeerGDNative<class_PacketPeerGDNative>`, :ref:`PacketPeerStream<class_PacketPeerStream>`, :ref:`PacketPeerUDP<class_PacketPeerUDP>`, :ref:`WebRTCPeer<class_WebRTCPeer>`, :ref:`WebSocketPeer<class_WebSocketPeer>`
  9. **Category:** Core
  10. Brief Description
  11. -----------------
  12. Abstraction and base class for packet-based protocols.
  13. Properties
  14. ----------
  15. +-------------------------+-------------------------------------------------------------------------------+
  16. | :ref:`bool<class_bool>` | :ref:`allow_object_decoding<class_PacketPeer_property_allow_object_decoding>` |
  17. +-------------------------+-------------------------------------------------------------------------------+
  18. Methods
  19. -------
  20. +-------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  21. | :ref:`int<class_int>` | :ref:`get_available_packet_count<class_PacketPeer_method_get_available_packet_count>` **(** **)** const |
  22. +-------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  23. | :ref:`PoolByteArray<class_PoolByteArray>` | :ref:`get_packet<class_PacketPeer_method_get_packet>` **(** **)** |
  24. +-------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  25. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`get_packet_error<class_PacketPeer_method_get_packet_error>` **(** **)** const |
  26. +-------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  27. | :ref:`Variant<class_Variant>` | :ref:`get_var<class_PacketPeer_method_get_var>` **(** :ref:`bool<class_bool>` allow_objects=false **)** |
  28. +-------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  29. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`put_packet<class_PacketPeer_method_put_packet>` **(** :ref:`PoolByteArray<class_PoolByteArray>` buffer **)** |
  30. +-------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  31. | :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 **)** |
  32. +-------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  33. Description
  34. -----------
  35. 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.
  36. Property Descriptions
  37. ---------------------
  38. .. _class_PacketPeer_property_allow_object_decoding:
  39. - :ref:`bool<class_bool>` **allow_object_decoding**
  40. +----------+----------------------------------+
  41. | *Setter* | set_allow_object_decoding(value) |
  42. +----------+----------------------------------+
  43. | *Getter* | is_object_decoding_allowed() |
  44. +----------+----------------------------------+
  45. Deprecated. Use ``get_var`` and ``put_var`` parameters instead.
  46. 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>`.
  47. **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).
  48. Method Descriptions
  49. -------------------
  50. .. _class_PacketPeer_method_get_available_packet_count:
  51. - :ref:`int<class_int>` **get_available_packet_count** **(** **)** const
  52. Return the number of packets currently available in the ring-buffer.
  53. .. _class_PacketPeer_method_get_packet:
  54. - :ref:`PoolByteArray<class_PoolByteArray>` **get_packet** **(** **)**
  55. Get a raw packet.
  56. .. _class_PacketPeer_method_get_packet_error:
  57. - :ref:`Error<enum_@GlobalScope_Error>` **get_packet_error** **(** **)** const
  58. Return 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>`).
  59. .. _class_PacketPeer_method_get_var:
  60. - :ref:`Variant<class_Variant>` **get_var** **(** :ref:`bool<class_bool>` allow_objects=false **)**
  61. Get a Variant. When ``allow_objects`` (or :ref:`allow_object_decoding<class_PacketPeer_property_allow_object_decoding>`) is ``true`` decoding objects is allowed.
  62. **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).
  63. .. _class_PacketPeer_method_put_packet:
  64. - :ref:`Error<enum_@GlobalScope_Error>` **put_packet** **(** :ref:`PoolByteArray<class_PoolByteArray>` buffer **)**
  65. Send a raw packet.
  66. .. _class_PacketPeer_method_put_var:
  67. - :ref:`Error<enum_@GlobalScope_Error>` **put_var** **(** :ref:`Variant<class_Variant>` var, :ref:`bool<class_bool>` full_objects=false **)**
  68. 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).