Multicast lock / bind adapter

I’ve made an application that joins to a spesific multicast group and visualises the data received. The app works fine in JAVA-mode and also in Android mode.

The problem is, that if the wlan-network is created from the same device in which the receiving client application is running, the data is not received (in practice creating when creating a hotspot). In case there is a separate device (eg. another phone/hotspot or router) providing the network, there are no problems.

I’ve understood that it is a question of somehow binding the client’s multicast group to a specific adapter. A term “multicast lock” might be related to this topic. I’ve not been able to find a solution.

I’m completely unfamiliar with java, having a c+±backgound.

@Aaro ===
as for wifi MulticastLock:

« Allows an application to receive Wifi Multicast packets. Normally the Wifi stack filters out packets not explicitly addressed to this device. Acqiring a MulticastLock will cause the stack to receive packets addressed to multicast addresses. Processing these extra packets can cause a noticeable battery drain and should be disabled when not needed »

code snippet (without imports and so on)

WifiManager monWifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
MulticastLock multicastLock = monWifi.createMulticastLock("multicastLock");
... ...

if (multicastLock != null) {////saving power (battery drain)
    multicastLock = null;

Thank you. I tested that, without success. My app is capable of receiving multicast as long as the network is not created by the phone where the app is running. So maybe it is not about the lock?

@Aaro ===
sorry: you have asked for multicastLock and i have answered for that; if it does not help i have to get some simple code from your app in order to test and see: of course multicastlock is not the unique possible guilty…

No problem, the the topic you hinted was interesting. I’ve later understood, that it might be necessary to (somehow…)

  • scan / find all the interfaces
  • select the one providing the wifi and
  • bind the socket to that interface / adapter