void Update()
    {
        LogMessage msg;

        while (LogQueue.GetNext(out msg))
        {
            switch (msg.Type)
            {
            case ELogType.Info:
                Debug.Log(msg.Message);
                break;

            case ELogType.Warning:
                Debug.LogWarning(msg.Message);
                break;

            case ELogType.Error:
                Debug.LogError(msg.Message);
                break;
            }
        }

        while (Net.GetNextEvent(out ConnectionEvent e))
        {
            switch (e.EventType)
            {
            case ConnectionEvent.EType.Connected:
                OnClientConnected?.Invoke(this, new ConnectionEventArgs(e.Connection));
                break;

            case ConnectionEvent.EType.Disconnected:
                OnClientDisconnected?.Invoke(this, new ConnectionEventArgs(e.Connection));
                break;
            }
        }

        if (Net.GetState() == ENetworkState.Running)
        {
            while (Net.GetNextMessage(out byte[] message, out ConnectionHandle connection, out ENetChannel channel))
            {
                NetworkData  networkData = null;
                ENetDataType type        = (ENetDataType)message[0];
                switch (type)
                {
                case ENetDataType.UserState:
                    networkData = new UserState();
                    break;

                case ENetDataType.ExperimentState:
                    networkData = new ExperimentState();
                    break;

                case ENetDataType.RandomState:
                    networkData = new RandomState();
                    break;

                case ENetDataType.ResponseState:
                    networkData = new ResponseState();
                    break;

                default:
                    Debug.LogError("Unknown NetDataType " + (int)type);
                    break;
                }
                if (networkData != null)
                {
                    networkData.Deserialize(message);
                    ReceivedNetworkDataEventArgs args = new ReceivedNetworkDataEventArgs(connection, networkData, type);
                    OnNetworkDataReceived?.Invoke(this, args);
                    //Debug.LogFormat("Received Network data of type '{0}'", type.ToString(), networkData);
                }
            }
        }
    }