在环回接口上模拟多播 [英] Simulating multicasting on loopback interface

查看:135
本文介绍了在环回接口上模拟多播的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个应该使用UDP多播的ruby中的网络应用程序。

I'm writing a network application in ruby which should use UDP multicasting.

我的问题是我想在localhost上运行多个实例以进行测试,但是多播仅在我将套接字绑定到真实网络接口时才有效。

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.

是否有某种方法可以为环回接口启用多播,以便所有127.0.0.x得到我发送的消息?
目前我启用多播:

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

此外,我注意到如果我例如将套接字绑定到127.0.0.4并发送消息,则在数据包中源ip是127.0.0.1无论如何......有没有办法设置源IP所以它显示了相同的IP我绑定了套接字到?

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允许您在回送设备上使用多播。对于其他操作系统,您可以启用也有类似的效果。

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.

这篇关于在环回接口上模拟多播的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆