public async Task <Package> Receive() { var result = await Client.ReceiveAsync(); Package package = null; if (result.RemoteEndPoint.Address.ToString() == "127.0.0.1") { MainEntry._Logger.Debug("Receive JsonPackage"); package = JsonPackage.Unpack(result.Buffer); } else { MainEntry._Logger.Debug("Receive TerminalPackage"); package = Package.Unpack(result.RemoteEndPoint, result.Buffer); } if (package != null) { Console.WriteLine(string.Format("Socket ReceiveData Package Type {0}", package._PackageType)); } else { Console.WriteLine(string.Format("Socket ReceiveData Package but Null")); } return(package); }
void ParseJsonFromWeb(JsonPackage pkg) { try { string cmd = pkg.GetString("cmd").ToString(); if (cmd == "check") { IPEndPoint iep = Program.GetTerminalIPEndPoint(pkg.GetString("ip")); Program.SendToTerminal(SendCheck(iep)); Program.SendToWeb(SendCmdJson("checkrsp", pkg.GetString("ip"), "ok")); } else if (cmd == "reset") { IPEndPoint iep = Program.GetTerminalIPEndPoint(pkg.GetString("ip")); Program.SendToTerminal(SendReset(iep)); Program.SendToWeb(SendCmdJson("resetrsp", pkg.GetString("ip"), "ok")); } else if (cmd == "startstop") { IPEndPoint iep = Program.GetTerminalIPEndPoint(pkg.GetString("ip")); Program.SendToTerminal(SendStartStop(iep, pkg.GetBool("isstart"))); } else if (cmd == "collection") { IPEndPoint iep = Program.GetTerminalIPEndPoint(pkg.GetString("ip")); Program.SendToTerminal(SendCollect(iep, pkg.GetInt16("n"),pkg.GetInt16("m"))); } else if (cmd == "mcu") { IPEndPoint iep = Program.GetTerminalIPEndPoint(pkg.GetString("ip")); Program.SendToTerminal(SendMCU(iep, pkg.GetString("binpath"))); } } catch (Exception ex) { Console.WriteLine(ex); } }
public async Task <Package> Receive() { var result = await Client.ReceiveAsync(); Package package = null; if (result.RemoteEndPoint.Address.ToString() == "127.0.0.1") { package = JsonPackage.Unpack(result.Buffer); } else { package = Package.Unpack(result.RemoteEndPoint, result.Buffer); } Console.WriteLine(string.Format("Socket ReceiveData Package Type {0}", package._PackageType)); return(package); }