# UDP broadcast packets being blocked

**URL:** <https://discuss.kotlinlang.org/t/udp-broadcast-packets-being-blocked/16549>\
**Category:** Android\
**Created:** [February 29, 2020, 2:51pm UTC](https://discuss.kotlinlang.org/t/udp-broadcast-packets-being-blocked/16549 "2020-02-29T14:51:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![asarangan](https://avatars.discourse-cdn.com/v4/letter/a/b3f665/32.png) [@asarangan](https://discuss.kotlinlang.org/u/asarangan)\
**Post date:** [February 29, 2020, 2:51pm UTC](https://discuss.kotlinlang.org/t/udp-broadcast-packets-being-blocked/16549/1 "2020-02-29T14:51:00Z")

</div>

Apparently UDP packets sent with a broadcast address such as 192.168.10.255 will be blocked by some versions of Android (which is the case with my Motorola MotoG phone). To get around this, some people recommended using WifiManager.MulticastLock when creating the listening socket. This works, but only temporarily. I am finding that only a handful of these broadcast packets get through before Android blocks them again. Does anyone have a suggestion? Below is the code snippet.

> val wifiManager: WifiManager = getApplicationContext().getSystemService(WIFI\_SERVICE) as WifiManager  
> val lock: MulticastLock = wifiManager.createMulticastLock(“Log\_Tag”)  
> lock.acquire();  
> val socketIn = MulticastSocket(4000)  
> val packetIn = DatagramPacket(buffer, buffer.size)  
> socketIn.receive(packetIn)

---

<div class="post-metadata">

**Author:** ![pdvrieze](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/pdvrieze/32/1882_2.png) [@pdvrieze](https://discuss.kotlinlang.org/u/pdvrieze)\
**Post date:** [February 29, 2020, 8:16pm UTC](https://discuss.kotlinlang.org/t/udp-broadcast-packets-being-blocked/16549/2 "2020-02-29T20:16:58Z")

</div>

You probably want to try stack overflow. This isn’t really a Kotlin question. I would suspect that you will need to read the documentation. Android has various policies trying to avoid app abuse.
