I want Peer(s) to be able to send DatagramPackets over a WIFI LAN for the sole purpose of discovering other Peers. So, I have each Peer made up of a Client(Sending packets) and a Server (listening for packets).
I have only been able to get this to work by using IPConfig on each machine to get their respective IPv4 Address and then using that as a paramter for the creation of the DatagramPacket:-
InetAddress server = InetAddress.getByName("THE IPv4 ADDRESS OF THE PEER'S SERVER
RUNNING ON THE OTHER MACHINE");
DatagramPacket sendPacket = new DatagramPacket(outBuffer, outBuffer.length,
server, serverPort);
Am I using broadcast (for peer discovery) in the right way here because it seems pretty rubbish to me if I am? I was under the assumption I could have a client on machineA fire off a packet into the LAN abyss and the Server running on machineB would be listening to the entire LAN and detect the packet. At the moment all I’m doing is manually using IPConfig on the machine running the server and typing that address in the DatagramPacket on the machine running the client, which just seems pointless.
I can use multicast just fine but I think broadcast is more what I need for peer discovery.
Help appreciated.
Use the broadcast address
255.255.255.255for both server and client.