My application will use a multicast channel for contacting peers on the network running the application, like mDNS. I have some sample code that works great on my local machine, but have a question how they will react on a multi router network.
This code is currently 2 apps but will eventually be one multi thread app.
This is the send code...
public static void Main()
{
UdpClient sock = new UdpClient();
IPEndPoint iep = new IPEndPoint(IPAddress.Parse("224.100.0.1"), 9050);
byte[] data = Encoding.ASCII.GetBytes("test message");
sock.Send(data, data.Length, iep);
sock.Close();
}
and this is the receve app code...
public static void Main()
{
UdpClient sock = new UdpClient(9050);
Console.WriteLine("Ready to receive...");
sock.JoinMulticastGroup(IPAddress.Parse("224.100.0 .1"), 50);
IPEndPoint iep = new IPEndPoint(IPAddress.Any, 0);
byte[] data = sock.Receive(ref iep);
string stringData = Encoding.ASCII.GetString(data, 0, data.Length);
Console.WriteLine("received: {0} from: {1}", stringData, iep.ToString());
sock.Close();
Console.ReadKey();
}
}
As you can see the send app is just a standard UDP socket, and does not join the multicast group. My question is will the UDP packet stop at the first router, or will it go out the default 128 TTL like it would for a non Multicast address?
Zig158