Android udp multicast with Ethernet

末鹿安然 提交于 2019-12-21 19:58:20

问题


Hello everyone,

I'm working on a project with udp multicast. I have a server sending multicast udp packets via an ethernet cable. I have spent weeks of work reading all the posts about multicast on android and I still can't receive any udp packet on my Asus Transformer Tablet, 4.1.

For some reasons, I can't put my code here, I will try to explain it carefully.

I have a simple MainActivity displaying some stuff. Almost everything is n the Oncreate method, and so is the line where I call a method named UDPreceiver. This method is defined in a class named UDPreceiverClass.

In UDPreceiver, there is the classic code for receiving multicast udp with : Multicastsocket, joingroup... I have tested this code in a java program on my computer and it is working.

Above in this very Oncreate method, I have acquired the wifi lock :

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

but I'm not sure if I have to use the same for an Ethernet connexion (I didn't find any other lock like that).

I have all the permissions in my manifest :

<uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>

and even more (I have added all the permissions that have a link with networking).

I will soon be able to try it on Wifi, but I'm not very confident neither.

My code is working on my Tablet if I send it in unicast, but not in Multicast !

Would you have any advice about that ? Is it the right place to put the Wifi lock ? Is it even working for Ethernet ? I know that some devices don't allow multicast, is it the case for the Asus transformer ?

I hope you will be able to help me. I know this is complicated without seeing the code but it is not possible, sorry.

Thank you very much !!

来源:https://stackoverflow.com/questions/18342534/android-udp-multicast-with-ethernet

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