Beispiel #1
0
        protected override void Update()
        {
            Stopwatch st = new Stopwatch();

            st.Start();

            Direction remoteMove;

            if (_connection != null)
            {
                Program.Log(this).Debug("Online");
                _connection.Send(new GamePacket(_input.Direction));
                // Placeholder, local and remote are currently out of sync
                remoteMove = _connection.GetReceived().Last().Direction;
            }
            else
            {
                Program.Log(this).Debug("Offline");
                remoteMove = Direction.Right;
            }

            _match.ApplyTurn(_input.Direction, remoteMove);
            _gameViewModel.Cells = _match.GetCells();

            st.Stop();
            Program.Log(this).Debug(String.Format("Update took {0} ms", st.ElapsedMilliseconds));
        }
        protected override void Update()
        {
            List <Player> players = _multicaster.GetReceived();

            Program.Log(this).Debug("Multicaster recieved {num} players", players.Count);
            _invitationManager.SyncConnections(players.Select(x => x.PublicEndPoint).ToHashSet());

            _playerView.Set(players, _invitationManager.GetContext());

            _multicaster.Send(_playerDataBox.Actor);
        }
        public void CanLoopback()
        {
            IPEndPoint localEP = new IPEndPoint(IPAddress.Loopback, 34525);
            UdpClient  client  = new UdpClient(localEP);
            string     msg     = "testingCanLoopback";

            using (var wrapper = new UdpWrapper <string>(client, localEP, true))
            {
                wrapper.Send(msg);
                Thread.Sleep(10);
                Assert.True(wrapper.Pending);
                var recieved = wrapper.GetReceived();
                Assert.False(wrapper.Pending);
                Assert.Single(recieved);
                Assert.Equal(recieved.Single(), msg);
            }
        }
        public void CanMulticastLoopback()
        {
            IPEndPoint multicastEP = Config.MulticastEndPoint;
            string     msg         = "testingCanMulticastLoopBack";

            UdpClient client = new UdpClient(multicastEP.Port);

            client.JoinMulticastGroup(multicastEP.Address);
            client.MulticastLoopback = true;

            using (var wrapper = new UdpWrapper <string>(client, multicastEP, false))
            {
                wrapper.Send(msg);
                Thread.Sleep(10);
                Assert.True(wrapper.Pending);
                var recieved = wrapper.GetReceived();
                Assert.False(wrapper.Pending);
                Assert.Single(recieved);
                Assert.Equal(recieved.Single(), msg);
            }
        }