5

I've got a computer with multiple NICs - and UDPClient's send method continually fails. Here's 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 that should be OK. The main problem is that I just can't get past the recvSock.Receive() line. I see the packets coming in over wireshark - but the code just won't process them...

Thoughts? Thanks in advance!

Dan

EDIT: I can confirm that the multi NICs is causing the problem --- the code works fine with a single NIC. Uncommenting the SetSocketOption line should allow it to work with multiple NICs, but it still fails.... thoughts?

3
  • To be clear, this "client" application [machine] has multiple NIC's or the the server your connecting to has multiple NIC's?? Commented Jul 6, 2010 at 0:46
  • Since I am having the same issue, I am willing to confirm: "the client application [machine] has multiple NICs". Typically the client is concerned with servers being on any of the multiple NIC networks. A server that has multiple NICs is only important if the client can see the same server via multiple client side NICs. Commented Jul 19, 2012 at 22:18
  • @Dan Did you find a workaround? I'm having the same issue Commented Mar 7, 2013 at 15:21

2 Answers 2

1

I had the same issue found this post, then found the solution at: UDP: Read data from all network interfaces

Basically Bind() to 0.0.0.0 doesn't work and you have to Bind() and JoinMulticastGroup() on every local ip address. Gotta love Microsoft for this one.

Sign up to request clarification or add additional context in comments.

Comments

0

The interface part is the important part in the following code:

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 ));

With interface being the (unicast) IP address of the receive network card.

2 Comments

This answer may be useful. But since it uses terminology from an radically different socket package from the original question, ..., who can tell?
The only relevance this answer has to the given question is that they both contain the word "IP."

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.