I have a scenario in which the router may be down when my multicast listener joins the group. In that scenario then multicast messages will never reach the listener.
So I plan on letting the listener timeout and then rejoin the multicast group.
The problem is that the following code does not ensure that the listener successfully registers and receives the multicast messages.
final MulticastSocket mcSocket = new MulticastSocket(POR);
// Join group before router started
mcSocket.joingGroup(mcAddress);
// wait until router starts
Thread.sleep(LONG_TIME);
mcSocket.leaveGroup(mcAddress);
// Join group after router started.
// Expected that this would re-register listener with router, but it doesn't
mcSocket.joingGroup(mcAddress);
// packet is never received
mcSocket.receive(packet);
So, what do I need to do to ensure that the listener re-registers with the router?