Multiplayer Issue - Broadcasting PacketPeerUDP when the subnet mask is 255.255.0.0

Godot Version

4.2

Question

Currently I am able to successfully create a LAN server browser with the tutorial provided by “FinePointCGI” on YouTube, the video is called “Creating a LAN Multiplayer Server Browser in Godot 4!” There’s a limitation to the demonstrated method though - broadcasting your UDP packages only works when your subnet mask is 255.255.255.0, which is usually the case with the smaller local networks. My University’s subnet mask is 255.255.0.0, so broadcasting does not work.

For reference, I use code

broadcaster = PacketPeerUDP.new()
	broadcaster.set_broadcast_enabled(true)
	broadcaster.set_dest_address(broadcast_adress, listen_port)

which works when I am at home, and:

broadcast_adress = xxx.xxx.xxx.255

and does not work when I am at University and use

broadcast_adress = xxx.xxx.xxx.255

or

broadcast_adress = xxx.xxx.255.255

You can likely detect the correct subnet mask to use based on the local IP address, which you can retrieve using IP.get_local_addresses(). You’ll have to filter the returned array to contain only addresses that start with 10., 172.16. and 192.168., then pick the first one in the array (in case there are multiple). This won’t be 100% reliable though and will require some finetuning.

However, on your university’s network, you’ll hit another problem: firewalls. University and corporate networks generally block a lot of ports, especially UDP ports as these are associated with gaming. You’ll have to look into using a VPN to avoid port restrictions (at your own risk).

1 Like