Receiving a UDP multicast

28 Apr 2012

After looking at a lot of code examples on this forum I am still confused as to how a client application should join an existing multicast group on the LAN. Most of the examples refer to multicasting as opposed to listening. I tried this code ..

  Host multicast(IpAddr(224,192,32,19), 22600); //Join multicast group
  udp.setOnEvent(&onUDPSocketEvent);
  udp.bind(multicast);
  printf("listening..\r\n");  
  while(true) {
    Net::poll();
  }

.. which just sits there waiting. I am wondering whether I should not be sending a join request to the device that is multicasting? If so, anyone know what to send?

Paul

28 Apr 2012

Hi Paul,

Not tried this yet but from what I know about UDP your code should just sit there and listen for packets with the matching address and port. Then when a packet to the specified multicast address is received it calls the onUDPSocketEvent callback function. Guessing this is not being called. You wouldnt need to send anything out to the host sending the multicast.

Have you tried wireshark to see what messages are being sent. Just setup the filtering to look for UDP multicast packets.

you've probably already done this anyway!

Cheers

Andy

29 Apr 2012

Thx Andy,

Got it working briefly by putting some delay (500ms) in the while loop.

However, this was short-lived.

So far I have failed to install wireshark on Mac OS/X 10.6 - will keep trying.

I guess I should also read up on the multicast protocol :-(

Paul

29 Apr 2012

Now I got wireshark going I think I see what's happening. "Binding" to the multicast port seems to grab it and stop the mac app from receiving the multicast packets that are going out.

The only IGMP packets that appear are the ones from the mac app starting up.

The only reason it worked briefly was that by a fluke I managed (unintentionally) to switch the IPs of the mac and the mbed after the mac had joined the multicast group.

So, what I need is to send an IGMP packet to the multicast port rather than bind to it.

Once again I'm stuck as I do not see this option in the UDPSocket (in Library EthernetIf)

Looking again at the api doc I see

UDPSocketErr bind	(	const Host & 	me	 ) 	
Binds the socket to local host or a multicast address.

This implies that there is a way - but what's that cryptic &me all about?

Anyone know of a facility in mbed to join a multicast group?

Thx. Paul

30 Apr 2012

I think you will need to find an example of using IGMP with the lwIP network stack which forms the basis of the mbed network stack that you appear to be trying to use.

I can find some documentation for the IGMP APIs supported by lwIP here: http://www.nongnu.org/lwip/igmp_8c.html Unfortunately I don't have any experience with this API or IGMP so I can't be of any more help :(

30 Apr 2012

Thx Adam,

Yes, the call in lwip is igmp_joingroup(). Given the above observation that this is supposed to be supported by the EthernetIf library I am wondering whether this is in place but failing in execution.

The post here suggests that this may be the case http://mbed.org/forum/mbed/topic/919/

Paul