When I start multiple instances of application listening on the same UDP port, only the last receives datagrams. Is there any way to send data to all instances other than sending broadcast (broadcasts are received in all instances)?
My application (commandline):
UdpClient client = new UdpClient();
client.Client.SetSocketOption(
SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
client.Client.Bind(new IPEndPoint(0, 7894));
client.EnableBroadcast = true;
Console.WriteLine("Press key to send datagram");
while (true)
{
if (client.Available > 0)
{
IPEndPoint ep = null;
client.Receive(ref ep);
Console.WriteLine("Received");
}
if (Console.KeyAvailable)
{
Console.ReadKey();
client.Send(new byte[] { 1 }, 1, new IPEndPoint(IPAddress.Parse("127.0.0.1"), 7894));
Console.WriteLine("Sent");
}
}
Is there any way to send data to all instances other than sending broadcast
Yes. read aboutmulticast
– Eser