UDPClient Multicast Accepts Failure on a Computer with Multiple Network Adapters

I have a computer with several network adapters, and the UDPClient sending method constantly fails. Here is the code:

        private static void receiveData()
    {
        recvSock = new UdpClient(PORT);
        //recvSock.Client.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.MulticastInterface, mainInterface);
        recvSock.JoinMulticastGroup(IPAddress.Parse(IP), 50);

        IPEndPoint iep = new IPEndPoint(IPAddress.Any, 0);

        while (true)
        {
            byte[] data = recvSock.Receive(ref iep);

            // Do not include messages from us
            if (myIPs.Contains(iep.Address))
                continue;

            string stringData = Encoding.ASCII.GetString(data, 0, data.Length);
            Console.WriteLine("received: " + stringData);

        }
    }

PORT = 5000 and IP = 224.5.6.7, so this should be OK. The main problem is that I just can't get past the recvSock.Receive () line. I can see the packets go through wirehark - but the code just doesn't handle them ...

Thoughts? Thanks in advance!

Dan

EDIT: I can confirm that a lot of network adapters are causing the problem - the code works fine with one network adapter. Disarming the SetSocketOption string should allow it to work with multiple network adapters, but still fail ... thoughts?

+5
2

, , : UDP:

Bind() 0.0.0.0 , () JoinMulticastGroup() IP-. Microsoft .

+1

:

unsigned long interface;
ip_mreq mreq;

_parseHostname( _description->getInterface(), interface );
mreq.imr_multiaddr.s_addr = _writeAddress.sin_addr.s_addr;
mreq.imr_interface.s_addr = interface;

setsockopt( _readFD, IPPROTO_IP, IP_ADD_MEMBERSHIP,
                (char*)&mreq, sizeof( mreq ));

, () IP- .

0

All Articles