Android 11 Won't Receive Packets sent to multicast Address

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By powerpoint45

I’m attempting to add a simple lobby that works over LAN to my Godot Project. I found
this GitHub example
and have been trying to get it to work on Android. I have enabled ChangeWifiMulticast and Internet permissions. The example works fine on Android 10 devices but my Pixel 4a Android 11 device is not able to receive any packets when discovering and get_available_packet_count() returns 0. Android 11 is able to Host but is not able to discover. No errors are seen over logcat. Does anyone know a workaround to get this working on Android 11 to receive multicast packets?

The main classes are as follows:
ServerAdvertiser (works in Android 11)

extends Node
class_name ServerAdvertiser

const DEFAULT_PORT := 3111

# How often to broadcast out to the network that this host is active
export (float) var broadcast_interval: float = 1.0
var serverInfo := {"name": "LAN Game"}

var socketUDP: PacketPeerUDP
var broadcastTimer :=
var broadcastPort := DEFAULT_PORT

func _enter_tree():
	broadcastTimer.wait_time = broadcast_interval
	broadcastTimer.one_shot = false
	broadcastTimer.autostart = true
	if get_tree().is_network_server():
		broadcastTimer.connect("timeout", self, "broadcast") 
		socketUDP =
		socketUDP.set_dest_address('', broadcastPort)

func broadcast():
	#print('Broadcasting game...')
	var packetMessage := to_json(serverInfo)
	var packet := packetMessage.to_ascii()

func _exit_tree():
	if socketUDP != null:

ServerListener(does not work in Android 11)

  extends Node
    class_name ServerListener
    signal new_server
    signal remove_server
    var cleanUpTimer :=
    var socketUDP :=
    var listenPort := ServerAdvertiser.DEFAULT_PORT
    var knownServers = {}
    # Number of seconds to wait when a server hasn't been heard from
    # before calling remove_server
    export (int) var server_cleanup_threshold: int = 3
    func _init():
    	cleanUpTimer.wait_time = server_cleanup_threshold
    	cleanUpTimer.one_shot = false
    	cleanUpTimer.autostart = true
    	cleanUpTimer.connect("timeout", self, 'clean_up')
    func _ready():
    	if socketUDP.listen(listenPort) != OK:
    		print("GameServer LAN service: Error listening on port: " + str(listenPort))
    		print("GameServer LAN service: Listening on port: " + str(listenPort))
    func _process(delta):
    	if socketUDP.get_available_packet_count() > 0: #RETURNS 0 in Android 11
    		var serverIp = socketUDP.get_packet_ip()
    		var serverPort = socketUDP.get_packet_port()
    		var array_bytes = socketUDP.get_packet()
    		if serverIp != '' and serverPort > 0:
    			# We've discovered a new server! Add it to the list and let people know
    			if not knownServers.has(serverIp):
    				var serverMessage = array_bytes.get_string_from_ascii()
    				var gameInfo = parse_json(serverMessage)
    				gameInfo.ip = serverIp
    				gameInfo.lastSeen = OS.get_unix_time()
    				knownServers[serverIp] = gameInfo
    				print("New server found: %s - %s:%s" % [, gameInfo.ip, gameInfo.port])
    				emit_signal("new_server", gameInfo)
    			# Update the last seen time
    				var gameInfo = knownServers[serverIp]
    				gameInfo.lastSeen = OS.get_unix_time()
    func clean_up():
    	var now = OS.get_unix_time()
    	for serverIp in knownServers:
    		var serverInfo = knownServers[serverIp]
    		if (now - serverInfo.lastSeen) > server_cleanup_threshold:
    			print('Remove old server: %s' % serverIp)
    			emit_signal("remove_server", serverIp)
    func _exit_tree():
:bust_in_silhouette: Reply From: powerpoint45

I was able to get it to work by setting socketUDP.set_broadcast_enabled (true) in _ready of ServerListener

:bust_in_silhouette: Reply From: PranshuTG

it works in older versions of godot

*Used to
i just tried again and it failed

PranshuTG | 2021-08-03 07:16