1

I got a bunch of clients(slaves) that listen to the messages from the server(master). I am trying to create a utility to discover the clients. So in order to do that, I am going to broadcast a message to the subnet IP address (192.168.1.255). So far so good. Now when I receive the packet (DatagramPacket) I am going to use the getAddress method to figure out the client IP addresses. But my question is after I broadcast the message then all the clients sends the response back but when I receive the response with .receive method from which client I received the response and what should I do to get all the client IP addresses? Do I need to send the message from the master several times and check the response each time and check the packet to get the address? What is the best way to do that? Any help appreciated!

omid
  • 21
  • 4
  • 1
    "_I am going to broadcast a message to the subnet IP address (192.168.1.255)_" That is completely wrong. The correct way to do that is to use multicast. Broadcast interrupts _every_ host on the network, including things like routers switches, printers, etc. In fact, broadcast is being deprecated, and IPv6 does not have broadcast, so you could not update this to support IPv6. Have the clients subscribe to a specific multicast group, and the server can send a message to that group. The clients can then respond with unicast. – Ron Maupin Feb 14 '20 at 23:31
  • Would you please elaborate more? What exactly do you mean by "Have the clients subscribe to a specific multicast"? The slave devices are IOT devices that responds to a specific messages. – omid Feb 14 '20 at 23:56
  • OK. If these are IoT devices, then you really need to be prepared for IPv6, and IPv6 does not support broadcast at all. The applications on the hosts need to subscribe to a multicast group, probably one you choose in the Organization-Local scope of `239.0.0.0/8`. There may already be a specifically assigned multicast group to which the application on the devices subscribe. You can review the _[IANA IPv4 Multicast Address Space Registry](https://www.iana.org/assignments/multicast-addresses/multicast-addresses.xhtml)_ for registered multicast groups. – Ron Maupin Feb 15 '20 at 00:04
  • That does not work as the IoT device provider has not assigned any group for the devices. Like EchoNet that has a group these devices does not have any group. I tried to broadcast the message but when I check the response packet IP address it seems it is my laptop IP which I am sending the message from it. Why is that so? Any help appreciated – omid Feb 19 '20 at 22:53

0 Answers0