0

I want to send message (question:if particular file available or not) and want answer from other android devices (if file is available:yes).For this I am sending udp broadcast message on local network to ask devices at once and afterwards sending file with tcp protocol which works fine. But sometimes android device doesn't receive udp messages on screen off. I have also acquired wake lock and multicast lock in broadcast receiver which detects screen off but it doesn't work.Please help! Thanks..

 PowerManager powerManager =             
(PowerManager)context.getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wakeLock =  powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MyWakelockTag");
        wakeLock.acquire();




WifiManager.MulticastLock multicastLock = wifiManager.createMulticastLock("lockWifiMulticast");
                                multicastLock.acquire();
          WifiManager.WifiLock wifiLock = wifiManager.createWifiLock(WifiManager.WIFI_MODE_FULL_HIGH_PERF,"MyWifiLock");
                                wifiLock.acquire();
Hammad Ali Khan
  • 138
  • 1
  • 11
  • UDP is connectionless and unreliable. If you use UDP, you must have no expectation that anything sent with UDP will ever arrive at the destination. If you want to be sure it will arrive, you must use a different protocol, e.g. TCP. – Ron Maupin Nov 05 '16 at 15:29
  • I know but this problem is related to android. It is not receiving any udp packet after screen is off. – Hammad Ali Khan Nov 05 '16 at 15:39
  • My point is that you shouldn't care because you don't care when you send the UDP. It shouldn't matter if the UDP is received, or not. If it does matter, then you shouldn't be using UDP. – Ron Maupin Nov 05 '16 at 15:41
  • But what is alternate way if i want to send message to the all android devices connected in local network at once like i have to ask all devices at local network for a file (e.g anybody has abc.mp4 file) and the reply would come ( yes i have the video file) can you please tell what would i do in this scenerio.. – Hammad Ali Khan Nov 05 '16 at 15:48
  • You may need to use a different protocol above UDP, or even create your own protocol for reliability, either to replace or augment UDP. There are other reasons that UDP may not be received, too, and that needs to enter your equation. Your paradigm may need to change, and the devices may need to actively send requests to see if the file is available. There are all sorts of things you could do. – Ron Maupin Nov 05 '16 at 15:52
  • Is it easy to make a new protocol? Is it possible to send msg to all devices using tcp at once. Do you know any reliable protocol other than tcp ? Do you know any better way to ask for file? – Hammad Ali Khan Nov 05 '16 at 16:04
  • There are all kinds of protocols out there. Many will provide reliability on top of UDP. Some are proprietary,and so are not. The ones which add reliability to UDP operate above UDP, and many use some or all of the TCP features. You just need to do some research to find the one you want. – Ron Maupin Nov 05 '16 at 16:09
  • Look at [this question](http://stackoverflow.com/q/107668/3745413) and search the Internet for `reliable udp`. – Ron Maupin Nov 05 '16 at 16:16
  • I am also facing the same issue. Have you got any solution to overcome this issue? – somia Mar 21 '18 at 17:15

0 Answers0