Send UDP packet via a specific port

Godot Version

4.3.stable

Question

How can you send a UDP packet from a specific local port?

I’m using

	var peer = PacketPeerUDP.new()
	peer.set_dest_address(address, port)
	peer.put_packet(buffer)

to send a packet, but I couldn’t find any documentation on how to specific which port I’m sending a packet from.

I’m looking for a way to emulate this netcat command:

echo "buffer content" | nc -6u address port -p local_port

I made a godot-proposal post about it, because I couldn’t find anything on how to send packets from specific ports, either in the documentation OR the actual godot C++ souce code.

If anyone is interested, please give it a thumbs up. This can be used to help with NAT traversal - so it would help with networking of any peep to peep game.

This can be done via the PacketPeerUDP.bind() method. I will see if I can suggest a change to the documentation to explain this.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.