Receive UDP in Android Marshmallow

Viewed 1259

I'm having problems to receive constantly the UDP packets from the server with new Nexus 5X (Marshmallow)

I have another real devices that receive all UDP packets, but it seems that something changed in Android API 23.

CODE:

Anyone with the same problem?

                        if (s == null || s.isClosed()){


                            Log.v("udp", "----------------------------------------------------new socket---------------------------------");


                            s = new DatagramSocket(null);
                            s.setReuseAddress(true);
                            s.setBroadcast(true);
                            s.setSoTimeout(5000);
                            s.bind(new InetSocketAddress(8002));
                            p = new DatagramPacket(message, message.length);

                            try{
                                Thread.sleep(100);
                            }
                            catch(Exception e){

                            }
                        }



                        //Log.v("test","---------------------------------------------------- Pas1 ---------------------------------");
                        message = new byte[100];
                        //p = new DatagramPacket(message, message.length);
                        p.setLength(message.length);

                        s.receive(p);

The problem is:

I receive randomly the broadcast packets, meanwhile in other real devices I receive all.

I'm sure that something was changed in android api 23. It seems that the receive function only "triggers" if it has a packet in the buffer, but if it's called without it "inside", the sockettimeout appears.

Thanks!

2 Answers
Related