Why multicast socket starts receiving packets only after sending any packet to socket on receiver side first?


I have a strange behavior of ZeroTier on Android.
I am creating MutlicastSocket in the common way in Kotlin:

val networkInterface = NetworkInterface.getByName(“tun0”)
val groupAddress = InetSocketAddress(“”, 5555)
val socket = MulticastSocket(5555)
socket.reuseAddress = true
socket.timeToLive = 16
socket.joinGroup(groupAddress, networkInterface)

But it does not start listening incoming data until I send anything, even empty packet into VPN:

// This is a life hack to make multicast work on Zero Tier VPN
socket.send(DatagramPacket(ByteArray(0), 0, 0, groupAddress))

Is it some specific how multicast works on ZeroTier? Or what may be wrong?

Furterhmore, if I send any packet at least once, then I can reconnect to multicast group any amount of times and even can reboot the device.

It seems ZeroTier does not forward multicast packet to nodes which never send sometging to network.

It is very strange. Can we debug this case with any ZeroTier support team?

So mobile operating systems are strange and limited beasts. Android doesn’t allow us to enable Multicast on the interface they give us directly. Before Android 10 was released, we could poll /proc/net/igmp to determine what multicast groups that ZeroTier should listen to, and things were good.

Android 10 was released and it included a lot of privacy updates, and we lost access to everything under /proc/net/. As such, we can no longer automatically listen to multicast groups that are listened to in other applications. The one workaround is the one you discovered. If you send a multicast packet over the ZeroTier network, the multicast emulation in ZeroTier will automatically start listening on that group as well.

1 Like

Thank you very much for the quick reply.
Then we will keep this life hack with empty multicast packet.
It is not a very big issue and it works pretty well.

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