开发者

Android not receiving broadcast UDP, but receiving directed UDP

开发者 https://www.devze.com 2023-04-13 02:02 出处:网络
I\'m having an issue where my Android device (An HTC Incredible running stock 2.3.4 rom) is not able to receive a broadcast UDP, but when I get the IP of the device (on the same network) and send the

I'm having an issue where my Android device (An HTC Incredible running stock 2.3.4 rom) is not able to receive a broadcast UDP, but when I get the IP of the device (on the same network) and send the packet directly to the IP, the phone immediately recognizes it and interprets it. I have tested with WireShark on two unrelated PCs, one not even on the same switch on this network, and both are able to see the packet (though they do call the packet "malformed") Yet the phone never receives (it doesn't require any data from the packet) so I'm wondering what's happening.

开发者_StackOverflow中文版

The same thing is happening in the emulator as well.

This is the current code.

                m_UDPSocket = new DatagramSocket( 9000 );
                m_UDPSocket.setBroadcast( true ); // unneeded?
                boolean finished = false; 

                byte[] buf = new byte[1024];
                DatagramPacket packet = new DatagramPacket(buf, buf.length);

                m_UDPSocket.setSoTimeout( 1000 );
                do {

                    finished = true;
                    try 
                    {
                        m_UDPSocket.receive(packet);    
                    }
                    catch ( SocketTimeoutException  e )
                    {
                        finished = false; 
                        System.out.print( "Socket recieve timed out" );                             
                    }

                } while( finished == false );
                System.out.print( buf );
                InetAddress address = packet.getAddress();

So is my phone rejecting the UDP broadcast packets for some reason, any way to test that it is receiving the packet on my phone? Is this the HTC Incredible issue HTC issue , and I need to program around this?

Thank you in advance for any help you can give me on this matter.


Try using a multicastlock . It seems that your phone is ignoring the packets that are not addressed to him directly (as a broadcast would be).

The answer is kind of late...but maybe it helps somebody that has the same issue. :)


Is this the HTC Incredible issue HTC issue

Looks very much like it.

and I need to program around this?

You can't, other than by relying on broadcast.

0

精彩评论

暂无评论...
验证码 换一张
取 消