开发者

Simulating multicasting on loopback interface

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?


Solaris allows you to use multicast on the loopback device. For other operating systems you can enable IP_MULTICAST_LOOP on the sender (Unix) or the receiver (Windows) for similar effect.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜