private async Task <string> SendCommandTcp(IRCommands irCommand) { try { var command = $"irsend SEND_ONCE philips {irCommand}"; using (var tcpClient = new TcpClient("10.110.166.91", 5739)) { using (var netStream = tcpClient.GetStream()) using (var streamReader = new StreamReader(netStream, Encoding.UTF8)) using (var streamWritter = new StreamWriter(netStream, Encoding.UTF8) { AutoFlush = true }) { tcpClient.SendTimeout = (int)TimeSpan.FromSeconds(10).TotalMilliseconds; tcpClient.ReceiveTimeout = (int)TimeSpan.FromSeconds(10).TotalMilliseconds; Logger.LogDebugMessage($"SendCommandToServer: Writing data to network stream writter"); await streamWritter.WriteLineAsync(command); Logger.LogDebugMessage($"SendCommandToServer: Reading data from network stream reader"); var response = await streamReader.ReadLineAsync(); Logger.LogDebugMessage($"SendCommandToServer: TCP Client length: {response.Length}"); return(response); } } } catch (Exception ex) { return(ex.Message); } }
private async Task <string> SendCommandLocal(IRCommands irCommand) { var command = $"irsend SEND_ONCE philips {irCommand}"; var result = BashHelper.ExecBashCommand(command); return(await Task.FromResult <string>(result.Message)); }
private async Task <string> SendCommandUdp(IRCommands irCommand) { try { var command = $"irsend SEND_ONCE philips {irCommand}"; var address = IPAddress.Parse("10.110.166.91"); var udpClient = new UdpClient(); udpClient.Connect(address, 5740); var bytes = Encoding.ASCII.GetBytes(command); await udpClient.SendAsync(bytes, bytes.Length); var result = await udpClient.ReceiveAsync(); var str = Encoding.ASCII.GetString(result.Buffer); udpClient.Close(); return(str); } catch (Exception ex) { return(ex.Message); } }
public async Task <string> SendCommand(IRCommands irCommand) { return(await SendCommandLocal(irCommand)); }