UDP Client not receiving messages on linux machines
Asked Answered
T

0

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;
            }
        }
Thornberry answered 23/7, 2020 at 6:22 Comment(5)
similar? #55104886 (Try using localIP = IPAddress.Any with "224.0.31.130" in example 1. – jdweng)Aril
Tried it. It didn't workedThornberry
Can you check if bash $:> ip maddr show on your linux machine shows a multicast address created by your program.Alliber
@Alliber 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 toThornberry
EDIT: Sorry, it does show the mc address while the app is runningThornberry

© 2022 - 2024 — McMap. All rights reserved.