Beispiel #1
0
        private void ListeningLoop()
        {
            bool disconnected = false;

            while (!disconnected)
            {
                try
                {
                    while (client.GetNextMessage(out Telepathy.Message msg))
                    {
                        switch (msg.eventType)
                        {
                        case Telepathy.EventType.Connected:
                            //We have finally connected. Tell the server who we are.
                            client.Send(authMessage.Serialize());
                            break;

                        case Telepathy.EventType.Data:
                            if (Message.TryInfer(msg.data, out Message inferred))
                            {
                                Receive(inferred);
                            }
                            break;

                        case Telepathy.EventType.Disconnected:
                            ConnectResult.TrySetResult(ConnectAttemptResult.GenericFail);
                            disconnected = true;
                            break;
                        }
                    }
                }
                catch { }
            }
        }