如何加入在C#源特定组播组(IGMPv3的) [英] How to join source specific multicast group in C# (IGMPv3)
问题描述
我们有一个C#应用程序,可以加入和多播组接收数据。这种运作良好。现在,我们想支持的IGMPv3,并能够加入组播组时指定源的IP地址。从MSDN文档,我不知道如何做到这一点。我发现下面的链接,似乎回答我的问题。
We have a C# application that can join and receives data from a multicast group. This works well. We now want to support IGMPv3 and be able to specify the IP of the source when joining a multicast group. From the MSDN documentation, I don't see how to do this. I have found the following link that seems to answer my question.
这里是我是如何实现这一点:
And here is how I implemented this:
byte[] membershipAddresses = new byte[12]; // 3 IPs * 4 bytes (IPv4)
Buffer.BlockCopy(multicastIp.GetAddressBytes(), 0, membershipAddresses, 0, 4);
Buffer.BlockCopy(sourceIp.GetAddressBytes(), 0, membershipAddresses, 4, 4);
Buffer.BlockCopy(localIp.GetAddressBytes(), 0, membershipAddresses, 8, 4);
socket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership, membershipAddresses);
不过,调用此错误SetSocketOption()时,我接收到一个SocketException:的请求的地址不在其上下文中有效
。
有人能指出我什么,我做错了什么?谢谢!
Can someone points me what I am doing wrong here? Thanks!
推荐答案
链接状态 SocketOptionName.AddSourceMembership
,你正在使用 AddMembership
。
The link states SocketOptionName.AddSourceMembership
, you are using AddMembership
.
这篇关于如何加入在C#源特定组播组(IGMPv3的)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!