Reputation: 169
Recently, I've changed my programme, which used TCP/IP before to UDP multicast, due to it using a lot less resources.
The problem I've encountered is that on few machines, where I planned to use it, there are two or more netwrok cards with connections running.
Can I choose which connection to multicast on from the program level? I tried changing different settings in system, like network priorities, but nothing worked.
For multicasting I use:
UdpClient publisher = new UdpClient(IP, Port);
publisher.Send(data, data.Length);
Where IP is one from multicast range (mainly 230.X.X.X).
In case of TCP/IP which was the case before, I could specify the EntryPoint on the IP specific for certain network card, but here it seems, it's not possible, because I need to send packets on multicast address rather than on my machine's one.
Thank you for any help in advance.
Upvotes: 1
Views: 1594
Reputation: 5424
You still have to call Bind
when using multicast. In other words, the listener gets to choose which NIC(s) they listen on. When you send out a message the local network stack will decide which NICs it needs to go out on automatically. That UdpClient class calls Bind with the data passed in the constructor. That needs to be your receiving endpoint. See here: https://msdn.microsoft.com/en-us/library/system.net.sockets.udpclient(v=vs.110).aspx . Then, when sending the data, use the Send
method that takes an endpoint parameter. Pass the target address in there.
Upvotes: 1