我正在编写一个服务,它发送多播消息,以便在网络上我的服务的多个实例之间进行通信。我正在设置两个侦听器并发送两次消息(主 NIC 上的 239.1.1.1,辅助 NIC 上的 239.1.1.2)一切正常,但有时 .2 多播组上的辅助侦听器会接收发送到的消息.1 多播组。知道为什么会发生这种情况吗?
这是我设置听众的方式:
PrimaryLocalEP = new IPEndPoint(primaryNIC.Address, vnc.DefaultUtilityPort);
PrimaryClient.ExclusiveAddressUse = false;
PrimaryClient.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
PrimaryClient.Client.Bind(PrimaryLocalEP);
PrimaryClient.JoinMulticastGroup(IPAddress.Parse("239.1.1.1"), primaryNIC.Address);
PrimaryClient.MulticastLoopback = false;
PrimaryRemoteEP = new IPEndPoint(IPAddress.Parse("239.1.1.1"), vnc.DefaultUtilityPort);
ReadThread = new System.Threading.Thread(ReadConnection);
ReadThread.IsBackground = true;
ReadThread.Name = "UDPReadConnection";
ReadThread.Start();
SecondaryLocalEP = new IPEndPoint(secondaryNIC.Address, vnc.DefaultUtilityPort);
SecondaryClient.ExclusiveAddressUse = false;
SecondaryClient.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
SecondaryClient.Client.Bind(SecondaryLocalEP);
SecondaryClient.JoinMulticastGroup(IPAddress.Parse("239.1.1.2"), secondaryNIC.Address);
SecondaryClient.MulticastLoopback = false;
SecondaryRemoteEP = new IPEndPoint(IPAddress.Parse("239.1.1.2"), vnc.DefaultUtilityPort);
ReadThreadSecondary = new System.Threading.Thread(ReadSecondaryConnection);
ReadThreadSecondary.IsBackground = true;
ReadThreadSecondary.Name = "UDPReadConnectionSecondary";
ReadThreadSecondary.Start();