Android Multicast socket stops listening

后端 未结 2 622
我在风中等你
我在风中等你 2021-01-20 09:59

I have a service on Android that listens and responds to packets it receives via multicast.

This works most of the time, but unfortunately, I\'m finding that every n

相关标签:
2条回答
  • 2021-01-20 10:57

    Note: This answer was meaningful when the question was asked in 2010, it is probably irrelevant today.

    I would think that changing wireless networks is pretty much akin to disabling and re-enabling the network (likely with a different IP and routing), so no surprise that things break.

    Perhaps registering for changes in the network info would give you the needed warning?

    http://developer.android.com/reference/android/net/ConnectivityManager.html#CONNECTIVITY_ACTION

    and associated pages

    0 讨论(0)
  • 2021-01-20 11:00

    Are you acquiring a multicast lock?

    WifiManager manager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
    MulticastLock lock = manager.createMulticastLock("lock name");
    lock.setReferenceCounted(true);
    lock.acquire();
    

    It also seems like certain devices block multicast:

    Multicast on Android 2.2

    0 讨论(0)
提交回复
热议问题