Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add examples to PacketPeerUDP class documentation #99015

Merged
merged 1 commit into from
Nov 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion doc/classes/PacketPeerUDP.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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() &gt; 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>
Expand Down
Loading