public void UdpCommunicator_Multicast() { var commSender = new UdpCommunicator() { MinPort = 10000, MaxPort = 10999, Timeout = 1000, EnvelopeHandler = NoOp }; commSender.Start(); var commReciever = new UdpCommunicator() { MinPort = 5000, MaxPort = 5000, Timeout = 1000, EnvelopeHandler = ProcessEnvelope5 }; commReciever.Start(); Random rand = new Random(); short gameId = (short)rand.Next(1, 1000); // Note, we can't test multiple receivers on the same host (localhost), because the // port number has to be the same for all receivers // Have the receivers join a Group Multicast address var multiCastAddress = new IPAddress(new byte[] { 224, 1, 1, 2 }); commReciever.JoinMulticastGroup(multiCastAddress); // Send message to Group Multicast address var msg = new StartGameMessage(gameId); var targetEndPoint = new IPEndPoint(IPAddress.Loopback, 5000); var env = new Envelope(msg, targetEndPoint); commSender.Send(env); Thread.Sleep(100); Assert.AreNotSame(msg, _lastIncomingEnvelope5); Assert.IsNotNull(_lastIncomingEnvelope5); Assert.IsNotNull(_lastIncomingEnvelope5.message); Assert.AreEqual(msg.msgId, _lastIncomingEnvelope5.message.msgId); Assert.AreEqual(msg.convId, _lastIncomingEnvelope5.message.convId); StartGameMessage msg2 = _lastIncomingEnvelope5.message as StartGameMessage; Assert.IsNotNull(msg2); Assert.AreEqual(msg.GameId, msg2.GameId); commReciever.DropMulticastGroup(multiCastAddress); commReciever.Stop(); commSender.Stop(); }