I am creating an application where there is a specific thread (MulticastListenerThread) that has a MulticastSocket and listens for UDP packets (datagrams) sent to the multicast group that the socket also listens on.
It works. I can join a multicast group, send a message to this group and receive it through MulticastSocket.
However, I would like to determine, from the perspective of the recipient, from which multicast group it received the packet. The following code gives me the address of the package creator, not the multicast group:
DatagramPacket packet = new DatagramPacket(buf, buf.length); mlcSenderSocket.receive(packet); String src_addr = packet.getAddress().getHostAddress();
The code for sending the package is as follows:
InetAddress address = InetAddress.getByName(dest); packet = new DatagramPacket(payload, payload.length, address, mlcEventPort); LLog.out(this,"[NC] MLC packet Sent to ev port MLC " + mlcEventPort + " and to addr " + address); mlcSenderSocket.send(packet);
Is it even possible to determine which group sent the packet?
Edit:
It seems to be impossible. As for the performance impact (I work on IoT devices), would I make the socket for each multicast group (and therefore the listener flow for each group) viable? Potentially, many groups can be combined (in terms of tens or hundreds even). If this is viable, then I just need to save the attached group address somewhere manually and access it as needed. Suggestions for other works are welcome!
user4346741
source share