How to receive Multicast packets on Android

后端 未结 4 1791
囚心锁ツ
囚心锁ツ 2021-01-04 19:25

I\'m trying to receive data from a multicast address, but the call to MulticastSocket.receive() blocks until a timeout takes place. I did some network sniffing and found ou

4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-04 20:02

    You need to do something like this

    WifiManager wifi = (WifiManager)getSystemService( Context.WIFI_SERVICE );
    if(wifi != null)
    {
        MulticastLock mcLock = wifi.createMulticastLock("mylock");
        mcLock.acquire();
    }
    

    Reference: http://developer.android.com/reference/android/net/wifi/WifiManager.MulticastLock.html

提交回复
热议问题