views:

114

answers:

1

Hi all,

I am currently sending out a DatagramPacket on a DatagramSocket and I receive just fine.. the problem is that I am receiving the packet I sent out. If I call the receive twice then it times out. Is there a way to ignore the first packet and receive the second.

Here is my code..

            socket = new DatagramSocket(8001);
            socket.setBroadcast(true);
            socket.setReuseAddress(false);
            DatagramPacket packet = new DatagramPacket(databytes, 7,
                getBroadcastAddress(), 8001);
            socket.send(packet);
            String localAddress = socket.getLocalAddress().toString();

            byte[] buf = new byte[1024];
            DatagramPacket receivepacket = new DatagramPacket(buf, buf.length);
            socket.setSoTimeout(5000);

            String temp = "";
            String delims = "[/]";
            while(true)
            {
                try{
                    socket.receive(receivepacket);
                    temp = receivepacket.getAddress().toString();
                    temp = temp.split(delims)[0];

                    if(temp != localAddress)
                    {   

                    }else
                    {
                        m_IPAddress = temp;
                        break;
                    }

                }catch (SocketException e){

                } catch (IOException e){
                    String temp1 = e.toString();
                }
            }
A: 

Check to see if the address is bound to one of your interfaces.

magaio
I'm pretty new to this.. how will that help me?
txagdev
Shouldn't it pick up the second packet when I call the receive a second time?
txagdev
Could there be a problem with the SecurityManager not accepting the packet coming from the broadcast channel?
txagdev