6

I have a program to discover clients on network, The class libraries which responsible for the discovery are .net standard 2. It works perfect on windows machines but now i need to run it on linux and my UdpClient not receiving the messages, Even tough i do see them sent to the right address from the clients with tcpdump on the linux machine, Which means they do get the discovery message and reply to it, Its just does not get to my UdpClient.Receive method in the code.

        private bool Start(IPEndPoint localEP, IPEndPoint remoteEP)
        {
            try
            {
                MulticastOption mcastOption = new MulticastOption(remoteEP.Address, localEP.Address);
                List<byte> msg = new List<byte>();
                // message type: Discovery
                

                byte[] discoveryMessage = CreateDiscoveryMessage();


                UdpClient managerClient = new UdpClient(localEP);
                managerClient.Client.SetSocketOption(SocketOptionLevel.IP,
                                                SocketOptionName.AddMembership,
                                                mcastOption);
                managerClient.Client.SetSocketOption(SocketOptionLevel.IP,
                                           SocketOptionName.MulticastLoopback,
                                           0);



                Task.Run(() =>
                {
                    while (!_token.IsCancellationRequested)
                    {
                        IPEndPoint ep = new IPEndPoint(IPAddress.Any, 0);

                        // Receive solicitation message
                        byte[] ret = managerClient.Receive(ref ep);
                        Console.WriteLine($"Message recieved from {ep.Address.ToString()}");
                    }
                });

                Task.Run(() =>
                {
                    while (!_token.IsCancellationRequested)
                    {
                        // Send discovery message
                        // Send discovery message_
                        managerClient.Send(discoveryMessage, discoveryMessage.Length, remoteEP);
                        Console.WriteLine("Message sent");
                        // wait 10 secs
                        Thread.Sleep(10000);
                    }
                });

                return true;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
                return false;
            }
        }
ATT
  • 921
  • 3
  • 13
  • 30
  • similar? https://stackoverflow.com/questions/55104386/udp-multicast-not-receiving-data (Try using localIP = IPAddress.Any with "224.0.31.130" in example 1. – jdweng) – ralf.w. Jul 30 '20 at 07:06
  • Tried it. It didn't worked – ATT Jul 30 '20 at 07:24
  • Can you check if **bash $:>** *ip maddr show* on your linux machine shows a multicast address created by your program. – sunriax Aug 02 '20 at 18:59
  • @sunriax I checked, It does`nt show the MC address im using. Any idea what could be the problam? Again - i do see the client sends messages to the linux machine with tcpdump to the MC address im sending to – ATT Sep 02 '20 at 11:42
  • EDIT: Sorry, it does show the mc address while the app is running – ATT Sep 02 '20 at 13:24

0 Answers0