I have a prototype Android app that is listening for multicast packets to 'discover' clients to communicate with. The socket set up is similar to this:
InetAddress group = InetAddress.getByName("228.1.2.3");
MulticastSocket s = new MulticastSocket(4000);
s.joinGroup(group);
This works very well when all the devices are connected via WiFi. I would like to support this with the phone acting as a portable hotspot. However, while all my devices appear to connect to the hotspot correctly I no longer receive multicast data. I'm wondering if there are restrictions that disallow this type of communication in hotspot mode, or if there are is any additional network configuration required to enable this? I've tried this on a couple different devices running Gingerbread and Froyo with no luck.
I've had the same problem and came up with a solution by the combination of @braden, @user707606 and the mainly the post by Chainfire in this Link.
Post in the link is nice but doesn't really offer any code samples but here it's. First you need to Acquire Multicast Lock, this is needed for some Android devices, didn't try in most of them but it was mentioned in some other posts, so I've included it in my code.
Permission is required, so first, add the permissions into your Manifest file.
Then the second step is to acquire multicast lock in your method.
And then, find your Wifi Network Interface
Later, create a Multicast socket with an available port and set your Wifi NetworkInterface.
Then the rest of your implementation remains the same. And once you are done with Multicast Lock, it's recommended to release it.
As this article show: https://plus.google.com/+Chainfire/posts/9NMemrKYnCd
MulticastSocket::setNetworkInterface()
would be the answer
you can find the wlan0 eth by :
Have a try and lemme know if it works or not in Hotspot mode...
Do you have the manifest permission and are you creating a lock?
For permission please see: 'CHANGE_WIFI_MULTICAST_STATE' in http://developer.android.com/reference/android/Manifest.permission.html
Also, to create a multicast lock... please see: http://developer.android.com/reference/android/net/wifi/WifiManager.MulticastLock.html