467,119 Members | 1,015 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,119 developers. It's quick & easy.

Unable to receive UDP multicast packets when having several network cards


I've two network cards(ethernet). They have their own sub-network.

I've to do some discovery on those subnetwork. This discovery will be made with a c# implementation of DNS-SD(Bonjour).

I've currently an issue with socket/UdpClient of c#: If I bind the socket or udpClient on IPAddress.Any, I receive only messages coming from one network card.

Here is a small example of what I tried:

Expand|Select|Wrap|Line Numbers
  1. private static void ReceiveMessagesOneClient(int port, string ip)
  2. {
  3.     Task.Factory.StartNew(() =>
  4.     {
  5.         using (var mUdpClientReceiver = new UdpClient())
  6.         {
  7.             var mReceivingEndPoint = new IPEndPoint(IPAddress.Any, port);
  8.             mUdpClientReceiver.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
  9.             mUdpClientReceiver.Client.Bind(mReceivingEndPoint);
  10.             mUdpClientReceiver.JoinMulticastGroup(IPAddress.Parse(ip), 255);
  11.             while (true)
  12.             {
  13.                 byte[] data = mUdpClientReceiver.Receive(ref mReceivingEndPoint);
  15.                 Console.WriteLine("Message received from {0, 18}", mReceivingEndPoint);
  16.             }
  17.         }
  18.     })
  19.         ;
  20. }
I can guarantee 100% that I receive mDNS traffic on each cards(controlled with wireshark for each network adapter). I can also guarantee that I'm the only one listening on this port( netstats -ano | find "5353" ).

I've made another test. If I specify the IP on which I wasn't receving any data before:

Expand|Select|Wrap|Line Numbers
  1. //I'm using the ip and port 5353, which are for mDNS
  2. private static void ReceiveMessagesOneClientOnOneIp(int port, string ip, String localIp)
  3. {
  4.     Task.Factory.StartNew(() =>
  5.     {
  6.         using (var mUdpClientReceiver = new UdpClient())
  7.         {
  8.             var mReceivingEndPoint = new IPEndPoint(IPAddress.Parse(localIp), port);
  9.             mUdpClientReceiver.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
  10.             mUdpClientReceiver.Client.Bind(mReceivingEndPoint);
  11.             mUdpClientReceiver.JoinMulticastGroup(IPAddress.Parse(ip), 255);
  12.             while (true)
  13.             {
  14.                 byte[] data = mUdpClientReceiver.Receive(ref mReceivingEndPoint);
  16.                 Console.WriteLine("Message received from {0, 18}", mReceivingEndPoint);
  17.             }
  18.         }
  19.     });
  20. }
I still receive nothing, but if I deactivate the network cards from which I receive data, I'm getting traffic on my card, without making any changes.

What could I've done wrong, that could be affected by disabling a network card that I'm not listening???

I could find a very similar issue here which is response less since 7 years.

I tried very various things, which had no effects on my issue:
  • Using several SocketOptions(MulticastInterface, DontRoute, Broadcast, NoDelay)
  • Use directly socket instead of UdpClient
  • Bind to IPAddress.Any, IPAddress.Parse(""), IPAddress.Parse("my-local-ip")

Another test that I made: when listening, I'm sending myself a multicast packet with a socket on the multicast ip/port, and I receive it! For me, it looks like that the OS isn't delivering packages to my socket, no idea why, and no idea about how to find a workaround.

I would appreciate any help since it makes already several day that I'm loosing on this.
Mar 7 '13 #1
  • viewed: 1286

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by Alphamacaroon | last post: by
6 posts views Thread by PHLICS_Admin | last post: by
2 posts views Thread by Terry | last post: by
1 post views Thread by =?Utf-8?B?SmVycnk=?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.