[SOLVED] Allow selection of local_port for sending UDP packets. #11114
Replies: 2 comments 3 replies
-
I am not familiar with networking but isn't bind method what you need? |
Beta Was this translation helpful? Give feedback.
-
Most ISPs have an IPv6 firewall active by default that blocks all incoming connections at the router level, so this won't work reliably unless the app uses UPnPv6 to open ports. This firewall is sometimes not controllable on some connection types (mainly mobile connections where you can't open any ports on it, including residential 4G/5G connections). |
Beta Was this translation helpful? Give feedback.
-
EDIT
Apperantly this already exist and it is done via the
PackedPeerUDP.bind
method.Suggestion
Currently you can send UDP packets via
however those packets would be send with a random local_port. Instead add a way to specify the local port via the
set_dest_address
as a 3rd optional argument.Why is this important
To enable NAT traversal. It is vital for many NAT traversal techniques to specify the port you send packets from.
This can then be used to improve the internet play of any peer to peer game, even without a STUN server.
Example use case
Two players with ipv6 want to connect over the internet without port forwarding.
Since ipv6 is rarely masks ports, you don't need a STUN server to determine their public_port, as it would coincide with the local_port.
This means the players can connect directly via hole punching in the following way:
player_a_local_port
andplayer_b_local_port
.Possible workarounds
Do not use Godot's PacketPeerUDP, and instead package
netcat-openbsd
as a binary and run it from godot to send packets. This is undesireable since trying package and run binaries on different machines and OSes would create a lot of additional problems.That being said here how currently you can achive the same result as the example use case, using the external program
net-cat-openbsd
.nc
isnetcat-openbsd
):player_a_local_port
andplayer_b_local_port
.Beta Was this translation helpful? Give feedback.
All reactions