public void BroadcastFromClientToAllServices()
        {
            UdpMessagingSystemFactory anOutputChannelMessaging = new UdpMessagingSystemFactory(new EasyProtocolFormatter())
            {
                UnicastCommunication   = false,
                AllowSendingBroadcasts = true
            };

            UdpMessagingSystemFactory anInputChannelMessaging = new UdpMessagingSystemFactory(new EasyProtocolFormatter())
            {
                UnicastCommunication = false,
                ReuseAddress         = true
            };

            ManualResetEvent    aMessage1Received = new ManualResetEvent(false);
            string              aReceivedMessage1 = null;
            IDuplexInputChannel anInputChannel1   = anInputChannelMessaging.CreateDuplexInputChannel("udp://127.0.0.1:8095/");

            anInputChannel1.MessageReceived += (x, y) =>
            {
                aReceivedMessage1 = (string)y.Message;
                aMessage1Received.Set();
            };

            ManualResetEvent    aMessage2Received = new ManualResetEvent(false);
            string              aReceivedMessage2 = null;
            IDuplexInputChannel anInputChannel2   = anInputChannelMessaging.CreateDuplexInputChannel("udp://127.0.0.1:8095/");

            anInputChannel2.MessageReceived += (x, y) =>
            {
                aReceivedMessage2 = (string)y.Message;
                aMessage2Received.Set();
            };

            IDuplexOutputChannel anOutputChannel = anOutputChannelMessaging.CreateDuplexOutputChannel("udp://255.255.255.255:8095/", "udp://127.0.0.1");

            try
            {
                anInputChannel1.StartListening();
                anInputChannel2.StartListening();

                anOutputChannel.OpenConnection();
                anOutputChannel.SendMessage("Hello");

                aMessage1Received.WaitIfNotDebugging(1000);
                aMessage2Received.WaitIfNotDebugging(1000);
            }
            finally
            {
                anOutputChannel.CloseConnection();

                anInputChannel1.StopListening();
                anInputChannel2.StopListening();
            }

            Assert.AreEqual("Hello", aReceivedMessage1);
            Assert.AreEqual("Hello", aReceivedMessage2);
        }
        public void MulticastFromServiceToClients()
        {
            UdpMessagingSystemFactory aMessaging = new UdpMessagingSystemFactory(new EasyProtocolFormatter())
            {
                UnicastCommunication    = false,
                ReuseAddress            = true,
                MulticastGroupToReceive = "234.1.2.3",
                MulticastLoopback       = true
            };

            ManualResetEvent     aMessage1Received = new ManualResetEvent(false);
            string               aReceivedMessage1 = null;
            IDuplexOutputChannel anOutputChannel1  = aMessaging.CreateDuplexOutputChannel("udp://127.0.0.1:8090/", "udp://127.0.0.1:8092/");

            anOutputChannel1.ResponseMessageReceived += (x, y) =>
            {
                aReceivedMessage1 = (string)y.Message;
                aMessage1Received.Set();
            };

            ManualResetEvent     aMessage2Received = new ManualResetEvent(false);
            string               aReceivedMessage2 = null;
            IDuplexOutputChannel anOutputChannel2  = aMessaging.CreateDuplexOutputChannel("udp://127.0.0.1:8090/", "udp://127.0.0.1:8092/");

            anOutputChannel2.ResponseMessageReceived += (x, y) =>
            {
                aReceivedMessage2 = (string)y.Message;
                aMessage2Received.Set();
            };

            IDuplexInputChannel anInputChannel = aMessaging.CreateDuplexInputChannel("udp://127.0.0.1:8090/");

            try
            {
                anInputChannel.StartListening();

                anOutputChannel1.OpenConnection();
                anOutputChannel2.OpenConnection();

                anInputChannel.SendResponseMessage("udp://234.1.2.3:8092/", "Hello");

                aMessage1Received.WaitIfNotDebugging(1000);
                aMessage2Received.WaitIfNotDebugging(1000);
            }
            finally
            {
                anInputChannel.StopListening();

                anOutputChannel1.CloseConnection();
                anOutputChannel2.CloseConnection();
            }

            Assert.AreEqual("Hello", aReceivedMessage1);
            Assert.AreEqual("Hello", aReceivedMessage2);
        }
        public void MaxAmountOfConnections()
        {
            IMessagingSystemFactory aMessaging = new UdpMessagingSystemFactory()
            {
                MaxAmountOfConnections = 2
            };
            IDuplexOutputChannel anOutputChannel1 = aMessaging.CreateDuplexOutputChannel("udp://127.0.0.1:8049/");
            IDuplexOutputChannel anOutputChannel2 = aMessaging.CreateDuplexOutputChannel("udp://127.0.0.1:8049/");
            IDuplexOutputChannel anOutputChannel3 = aMessaging.CreateDuplexOutputChannel("udp://127.0.0.1:8049/");
            IDuplexInputChannel  anInputChannel   = aMessaging.CreateDuplexInputChannel("udp://127.0.0.1:8049/");

            try
            {
                ManualResetEvent aConnectionClosed = new ManualResetEvent(false);
                anOutputChannel3.ConnectionClosed += (x, y) =>
                {
                    EneterTrace.Info("Connection closed.");
                    aConnectionClosed.Set();
                };


                anInputChannel.StartListening();
                anOutputChannel1.OpenConnection();
                anOutputChannel2.OpenConnection();
                anOutputChannel3.OpenConnection();

                if (!aConnectionClosed.WaitOne(1000))
                {
                    Assert.Fail("Third connection was not closed.");
                }

                Assert.IsTrue(anOutputChannel1.IsConnected);
                Assert.IsTrue(anOutputChannel2.IsConnected);
                Assert.IsFalse(anOutputChannel3.IsConnected);
            }
            finally
            {
                anOutputChannel1.CloseConnection();
                anOutputChannel2.CloseConnection();
                anOutputChannel3.CloseConnection();
                anInputChannel.StopListening();
            }
        }