0

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.

2
Contributors
2
Replies
17
Views
1 Year
Discussion Span
Last Post by Levellous
1

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.