I'm writing a network application in ruby which should use UDP multicasting.
My problem is that I want to run multiple instances for testing purposes on localhost, but multicasting only works if I bind the socket to the real network interface.
Is there some way to enable multicasting for the loopback interface, so that all the 127.0.0.x get the message I send? Currently I enable multicasting with:
ip = IPAddr.new('234.56.78.9').hton + IPAddr.new('0.0.0.0').hton
socket.setsockopt(Socket::IPPROTO_IP, Socket::IP_ADD_MEMBERSHIP,ip)
#socket.bind '127.0.0.1',1234 ##does not receive multicast :(
socket.bind '0.0.0.0',1234
Also, I noticed that if I e.g. bind the socket to 127.0.0.4 and send a message, in the packet the source ip is 127.0.0.1 anyway... is there a way to set the source IP so it shows the same IP I bound the socket to?