Esempio n. 1
0
        public async Task <string> SendMessageAsync(string msg)
        {
            try
            {
                await SendHelloPacketIfNeededAsync().ConfigureAwait(false);

                var requestHex = initialPacket.BuildMessage(msg, _token);
                await _udpClient.SendAsync(requestHex.ToByteArray(), _endpoint).ConfigureAwait(false);

                var responseHex = (await _udpClient.ReceiveAsync().ConfigureAwait(false)).Buffer.ToHex();
                var miioPacket  = new MiioPacket(responseHex);

                return(miioPacket.GetResponseData(_token));
            }
            catch (TimeoutException)
            {
                throw _timeoutException;
            }
        }
Esempio n. 2
0
        public string SendMessage(string msg)
        {
            try
            {
                SendHelloPacketIfNeeded();

                var requestHex = initialPacket.BuildMessage(msg, _token);
                _udpClient.SendTo(requestHex.ToByteArray(), _endpoint);

                var responseHex = _udpClient.Receive(ref _endpoint).ToHex();
                var miioPacket  = new MiioPacket(responseHex);

                return(miioPacket.GetResponseData(_token));
            }
            catch (TimeoutException)
            {
                throw _timeoutException;
            }
        }