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