Problem with MulticastSocket on Java-Android

只谈情不闲聊 提交于 2019-12-03 13:43:20

Diego,

By default, the Android WiFi stack filters out multicast packets. Take a look at http://developer.android.com/reference/android/net/wifi/WifiManager.MulticastLock.html.

You need something along the lines of:

  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    /* Turn off multicast filter */
    MulticastLock mcastLock = new MulticastLock();
    mcastLock.acquire();

    /* Process Multicast Packets */

  }

It appears that Multicast support in Android is not as solid as some of use might hope. See http://codeisland.org/2012/udp-multicast-on-android/

Ie whether it actually works out or may be device dependent. It is not working on my Nexus5.

https://code.google.com/p/android/issues/detail?id=51195

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!