Hellooo,

Is there a way to compare a datagram packet's IP address with the host's IP address? Because i have a client/server (client is acting as a client & server) class that uses multisocket to broadcast to every host it'll send the datagram to itself as well, which i don't necessary want. To work around this i'm thinking to only print the receiving datagram packet if it's not from the host.

I was thinking of using this:

if (receivingPacket.getAddress() != InetAddress.getLocalHost().getHostAddress())
{
    System.out.println(receivingMessage); // ReceivingMessage is just the receiving Packet's message
}

else
{
    System.out.println("Debugging purpose...Packet's IP matches Host's IP");
}

I don't think this is ideal but hey if it works it'll be great.

Recommended Answers

All 2 Replies

It's worth a try BUT...
== and != test for Objects being/not being exactly the same object (same address in memory).
You want to know if two different InetAddress objects represent the same IP address, for which you have to use their equals method

ooo that worked. Thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.