diff options
| author | Emanuil Chizhov <echizhov@disroot.org> | 2024-11-10 13:18:39 +0200 |
|---|---|---|
| committer | Emanuil Chizhov <echizhov@disroot.org> | 2024-11-10 18:34:29 +0200 |
| commit | 5516088c51bd58547de2600e3cfe67021cbce1dc (patch) | |
| tree | 47d86d9d7a2a94d5d9703aa1c5a50f457f61e8c9 | |
| parent | e65a23762b36b564eb94672031f37fdadba72333 (diff) | |
| download | redot-engine-5516088c51bd58547de2600e3cfe67021cbce1dc.tar.gz | |
Add examples to PacketPeerUDP class documentation.
Add examples for sending packets and listening for packets.
Fix documentation indentation.
Change tabs to spaced for codeblocks.
Fix typos
Remove typing in documentation code
Add a blank line to comply with style guidelines
Fix blank line to contain tabs
Remove tabs from empty code lines
Commit suggested changes by Mickeon
Use correct syntax for >
| -rw-r--r-- | doc/classes/PacketPeerUDP.xml | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/doc/classes/PacketPeerUDP.xml b/doc/classes/PacketPeerUDP.xml index 12d3178797..05b6e646c0 100644 --- a/doc/classes/PacketPeerUDP.xml +++ b/doc/classes/PacketPeerUDP.xml @@ -4,7 +4,32 @@ UDP packet peer. </brief_description> <description> - UDP packet peer. Can be used to send raw UDP packets as well as [Variant]s. + UDP packet peer. Can be used to send and receive raw UDP packets as well as [Variant]s. + [b]Example:[/b] Send a packet: + [codeblock] + var peer = PacketPeerUDP.new() + + # Optionally, you can select the local port used to send the packet. + peer.bind(4444) + + peer.set_dest_address("1.1.1.1", 4433) + peer.put_packet("hello".to_utf8_buffer()) + [/codeblock] + [b]Example:[/b] Listen for packets: + [codeblock] + var peer + + func _ready(): + peer = PacketPeerUDP.new() + peer.bind(4433) + + + func _process(_delta): + if peer.get_available_packet_count() > 0: + var array_bytes = peer.get_packet() + var packet_string = array_bytes.get_string_from_ascii() + print("Received message: ", packet_string) + [/codeblock] [b]Note:[/b] When exporting to Android, make sure to enable the [code]INTERNET[/code] permission in the Android export preset before exporting the project or using one-click deploy. Otherwise, network communication of any kind will be blocked by Android. </description> <tutorials> |
