0

I have an issue which I am confused. for example, if I want to join a multicast group 239.255.0.1:30001 to receive data. which interface should I bind to? I saw some people say to bind to that multicast address 239.255.0.1:30001. how about binding to the local machine interface such as eth0/eth1?

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
Michael D
  • 1,449
  • 5
  • 18
  • 31
  • See: http://stackoverflow.com/questions/14388706/socket-options-so-reuseaddr-and-so-reuseport-how-do-they-differ-do-they-mean-t – JHiant Dec 04 '14 at 16:01

1 Answers1

1

It depends on the OS you're targetting.

  • For Windows, bind to the local machine interface
  • For Linux & Mac/iOS (and possibly other users of BSD-style sockets), bind to the multicast address
  • For code that'll sort of work across both Windows & Linux, bind to INADDR_ANY (0). Note that you might then have to filter out unwanted traffic. Also, this won't work on Mac/iOS.
simonc
  • 41,632
  • 12
  • 85
  • 103
  • thank you. since I am using Linux, I would like know why to bind to the multicast address instead of local machine interface? – Michael D Nov 03 '11 at 01:22
  • @MichaelD I'm not sure why the API behaves in this way. You do need to use the interface address elsewhere - for the IP_ADD_MEMBERSHIP (and optionally IP_MULTICAST_IF) sockopts. – simonc Nov 04 '11 at 13:03