Esempio n. 1
0
        public void Update()
        {
            // Process incoming packets from clients.
            while (true)
            {
                var receiveAddr = new IPEndPoint(IPAddress.Loopback, 0);
                var packet      = RecvHelper.ReceiveNonBlocking(_udp, ref receiveAddr);
                if (packet == null)
                {
                    break;
                }

                if (!_clients.ContainsKey(receiveAddr))
                {
                    // This is a new client.
                    HandleNewClientConnection(receiveAddr);
                }

                _clients[receiveAddr].EnqueueReceive(receiveAddr, packet);
            }

            // Process all pending send operations for connected clients.
            foreach (var kv in _clients.ToArray())
            {
                kv.Value.Update();
            }
        }
Esempio n. 2
0
        public void Update()
        {
            while (true)
            {
                var receiveAddr = new IPEndPoint(IPAddress.Loopback, 0);
                var packet      = RecvHelper.ReceiveNonBlocking(_udp, ref receiveAddr);
                if (packet == null)
                {
                    break;
                }

                if (!receiveAddr.Equals(_target))
                {
                    // Packet was not from the server.
                    continue;
                }

                _server.EnqueueReceive(receiveAddr, packet);
            }

            _server.Update();
        }