I am working on a c# based application which is sending messages continuously using Multi-casting. Every thing works fine. The clients at thereceiving end receives messages continuously till the network is disconnected. But when I reconnect the network the client machines on the same network don't receive any messages till I collect all the messages on the same machine via receiving code.
Send Code:
using (UdpClient udpclient = new UdpClient())
{
IPAddress multicastaddress = IPAddress.Parse("239.0.0.222");
try
{
udpclient.ExclusiveAddressUse = false;
udpclient.MulticastLoopback = false;
udpclient.JoinMulticastGroup(multicastaddress);
IPEndPoint remoteep = new IPEndPoint(multicastaddress, 8191);
int j = udpclient.Send(byteBuffer, byteBuffer.Length, remoteep);
}
catch (Exception e)
{
udpclient.DropMulticastGroup(multicastaddress);
udpclient.Close();
}
finally
{
udpclient.DropMulticastGroup(multicastaddress);
udpclient.Close();
}
});
Receive Code:
var udpClientDispose = new UdpClient(_settingsViewModel.SyncPort);
var ipEndPoint = new IPEndPoint(IPAddress.Any, 8191);
IPAddress multicastaddress = IPAddress.Parse("239.0.0.222");
udpClientDispose.JoinMulticastGroup(multicastaddress, "192.168.0.12");
var timeElapsedSinceMasterMessageReceived = new Stopwatch();
Stopwatch sw = new Stopwatch();
sw.Start();
while (sw.ElapsedMilliseconds < 5000)
{
udpClientDispose.Receive(ref ipEndPoint);
}
udpClientDispose.Close();`
It Seems like all messages are getting collected at my system and there is a network jam on the particular multicast address i.e "239.0.0.222". As if I try to change the address it works but not again on "239.0.0.222".
Anyone knows the exact reason why is this happening and any valid solution to this.