Beispiel #1
0
 private void Broadcast(object obj)
 {
     while (true)
     {
         sender.Send("Hello", broadcastIp, port);
         Thread.Sleep(1000);
     }
 }
Beispiel #2
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();
        }
Beispiel #3
0
        private void PlayerUpdated(Player player)
        {
            var msg = string.Format(
                "pp;{0};{1};{2}",
                player.Body.X.ToString(CultureInfo.InvariantCulture),
                player.Body.Y.ToString(CultureInfo.InvariantCulture),
                player.Body.Name
                );

            Sender.Send(msg, Ip, Port);
            //Sandbox.Log.Publish(msg);
            //Sandbox.Log.Publish(Ip +":"+ Port);
        }
Beispiel #4
0
        private void OnPlayerUpdate(Player player)
        {
            for (int i = 0; i < Addresses.Count; i++)
            {
                var msg = string.Format(
                    "pp;{0};{1};{2}",
                    player.Body.X.ToString(CultureInfo.InvariantCulture),
                    player.Body.Y.ToString(CultureInfo.InvariantCulture),
                    player.Body.Name
                    );

                //Console.WriteLine(msg);
                Sender.Send(msg, Addresses[i], 1338);
                //Sandbox.Log.Publish(Addresses[i].Ip +":"+ Addresses[i].Port);
            }
        }
Beispiel #5
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();
        }