1

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?

William
  • 20,150
  • 8
  • 49
  • 91

1 Answers1

1

I would try a different strategy. I would set a longish read timeout, with setSoTimeout(), and if it expires I would then leave the group, sleep for a bit, then rejoin. That way it will happen every time, not just at startup. You probably need to sniff the network to make sure that IGMP JOIN messages are actually going out when you do the re-join.

user207421
  • 305,947
  • 44
  • 307
  • 483
  • :-) that's exactly the strategy I am using. I just left it out of the code above for clarity and brevity. I am about to start sniffing the packets but I suspect the subsequent IGMP join messages are being quenched, perhaps because I have already joined the group once. – William Jun 16 '14 at 08:27
  • Hmm, must have been really tired last night when I tested this. The rejoin *is* working. – William Jun 16 '14 at 09:36
  • I think a sleep between leave and join can make the difference. You can imagine that if they follow each other too closely they can both get 'optimized' away. – user207421 Jun 16 '14 at 09:52
  • Starting going nuts tonight because it had stopped working. It had decided to send the join messages to another network interface (I also have a virtual ethernet adapter). I now know how to direct to a specific adapter, but I had assumed it would send to all adapters. What determines which adapter it sends to when there are more than one? – William Jun 17 '14 at 18:30