Пример #1
0
        public T SendAndWaitForResponse <T>(NetworkMessage message)
        {
            Send(message);

            while (true)
            {
                Thread.Sleep(100);

                if (SpecificResponses.TryGetValue(message.MessageId, out NetworkMessage response))
                {
                    return((T)response.Data);
                }
            }
        }
Пример #2
0
        private void HandleMessage(string input)
        {
            var message = Serializer.Deserialize <NetworkMessage>(input);

            message.Received = DateTime.Now;

            if (message.MessageType == MessageTypes.Connected)
            {
                Id = (NetworkId)message.Data;
            }
            if (message.MessageType == MessageTypes.Disconnect)
            {
                Disconnect(false);
            }
            else if (message.ResponseTo != null && !message.ResponseTo.Value.Equals(NetworkId.Empty))
            {
                SpecificResponses.TryAdd(message.ResponseTo, message);
            }
            else
            {
                DataReceived?.Invoke(this, new NetworkDataRecievedEventArgs(message));
            }
        }