开发者

.NET Multicast Socket Error

I have an app that uses 2 multicast channels, so

_sock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
            IPEndPoint iep = new IPEndPoint(IPAddress.Any, 30002);
_sock.Bind(iep);
_sock.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership, new MulticastOption(IPAddress.Parse("239.255.0.2")));
...

later on, in the same app

_sock2 = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
            IPEndPoint iep = new IPEndPoint(IPAddress.Any, 30001);
_sock2.Bind(iep);
_sock2.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership, new MulticastOption(IPAddress.Parse("239.255.0.2")));

(notice the different ports开发者_StackOverflow社区).

When the execution point reaches the second bind an exception (HResult 0x80004005) is raised, warning me that only one protocol/address/port can be used...

I have done that in C++ apps so i think ther must be an error.

What is wrong with that?

Thank you in advance


Ok, I've got it:

_sock.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, 1); 

before the first bind

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜