简体   繁体   English

多播提要

[英]multicast feed

I'm being sent an xml feed via multicast, but don't know the multicast group address. 我正在通过多播发送xml提要,但不知道多播组地址。 Can I just use localhost instead; 我可以改用localhost吗? that is, 那是,

Socket socket = 
     new Socket(AddressFamily.InterNetwork,SocketType.Dgram,ProtocolType.Udp);
IPEndPoint ip = new IPEndPoint(IPAddress.Any,8888);
socket.Bind(ip);
socket.SetSocketOption
   (SocketOptionLevel.IP, 
    SocketOptionName.AddMembership, 
    new MulticastOption(IPAddress.Parse("127.0.0.1"),IPAddress.Any));

byte[] data = new byte[1024];
int length = socket.Receive(data);

... ...

No. 没有。

You (your client) needs to join the multicast group, you'll AddMembership to the multicast group IP, then connect. 您(您的客户端)需要加入多播组,将AddMembership添加到多播组IP,然后进行连接。

Otherwise you won't be able to receive the multicast feed. 否则,您将无法接收多播提要。 Your code would work with a UDP broadcast though. 您的代码可以与UDP广播一起使用。

Strictly speaking, if you open a listening port for multicast data on a non-multicast address, then you are essentially listening to standard UDP. 严格来说,如果您在非多播地址上打开用于多播数据的侦听端口,那么您实际上就是在侦听标准UDP。 The difference between multicast and UDP is in the IP address. 组播和UDP之间的区别在于IP地址。 Its a special IPV4 address range that is not tied to a fixed host. 它是不绑定到固定主机的特殊IPV4地址范围。 Rather it is recognized by the routers on the edges of your network in a pseudo publish-subscribe fashion. 而是由网络边缘的路由器以伪发布-订阅方式识别它。 Within your sub-net multicast is for all intents and purposes the same as broadcast. 在子网内,多播出于所有目的和目的与广播相同。

If you write to a multicast address, it is available to all hosts on your subnet. 如果写入多播地址,则该地址可用于子网上的所有主机。 If your router supports multicast, then it will provide it upstream to any clients that announce that they are interested in it. 如果您的路由器支持多播,则它将在上游将其提供给任何宣布对其感兴趣的客户端。 THink of it as publish/subscribe for subnets. 可以将其视为发布/订阅子网。

All of this to say, if you are looking for a localhost equivalent to multicast, then you probably need to look at broadcast instead. 所有这一切都说明,如果您正在寻找与多播等效的本地主机,则可能需要查看广播。

与单播不同,您确实需要知道多播的组地址。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM