Exemple #1
0
        /// <summary>
        /// Listen to the server
        /// </summary>
        private void ListenToServer()
        {
            while (!_cancellationTokenSource.Token.IsCancellationRequested)
            {
                if (ClientSocket.Poll(10, SelectMode.SelectRead) && ClientSocket.Available == 0)
                {
                    OnConnectionLost?.Invoke();
                    break;
                }

                AbstractPacketBuilder.ReadAndHandlePacketFromSocket(ClientSocket, _packetBuilder, this);
            }
        }
Exemple #2
0
        private void ListenClients()
        {
            while (!_cancellationTokenSource.Token.IsCancellationRequested)
            {
                lock (_lock)
                {
                    foreach (var client in _clients)
                    {
                        if (client.Available == 0)
                        {
                            continue;
                        }

                        AbstractPacketBuilder.ReadAndHandlePacketFromSocket(client, _packetBuilder, this);
                    }
                }
            }
        }