Exemplo n.º 1
0
        public void ShouldReceiveMessagesFromMultipleSources()
        {
            var listenerPort = 20002;

            var expectedMessages = new string[] { "msg 1", "msg 2" };

            var listener = new UdpMessageListener(listenerPort);
            var count    = 0;

            listener.Listen((actualMessage, address) =>
            {
                count++;
                Assert.IsTrue(expectedMessages.Contains(actualMessage));
                if (count >= 2)
                {
                    AsyncAssert.Done();
                }
            });

            var writer1 = new UdpMessageSender();

            var writer2 = new UdpMessageSender();

            writer1.Send(expectedMessages[0], "localhost", listenerPort);
            writer2.Send(expectedMessages[1], "localhost", listenerPort);

            AsyncAssert.Wait();

            writer1.Dispose();
            writer2.Dispose();
            listener.Dispose();
        }
Exemplo n.º 2
0
        public void ShouldReceiveAtLeastMessage()
        {
            var listenerPort    = 20000;
            var expectedMessage = "Opa! excelente~";

            var listener = new UdpMessageListener(listenerPort);

            listener.Listen((actualMessage, address) =>
            {
                Assert.AreEqual(expectedMessage, actualMessage);
                AsyncAssert.Done();
            });

            var writer = new UdpMessageSender();

            writer.Send(expectedMessage, "localhost", listenerPort);

            AsyncAssert.Wait();

            writer.Dispose();
            listener.Dispose();
        }
Exemplo n.º 3
0
 public void Dispose()
 {
     Sender.Dispose();
 }
Exemplo n.º 4
0
 public void Dispose()
 {
     broadcastLoop.Abort();
     sender.Dispose();
     listener.Dispose();
 }