I am writing a game in Java using libGDX
. I want to add local area network discovery into the game, so players will only have to press a button to start a multiplayer game. To achieve this, each client broadcasts UDP
packets to a certain port (255.255.255.255:40667
) and listens for other incoming packets on this port to create a list of other players on the network.
This works perfectly, but the packets which were broadcasted by a machine are also received by it.
For example:
If there are 2 machines on the network with the program running
Machine 1 (192.168.1.137)
Machine 2 (192.168.1.111)
Then the 1st machine receives packets from 192.168.1.111
AND from 192.168.1.137
I am trying to find a way to determine if the packet came from my own address, but I can't figure it out.
InetAddress.getLocalHost()
returns 127.0.1.1
, and reading the local address from the outbound socket returns 0.0 0.0
How do I determine if the packet was sent from the same machine?
Thanks