public int sendCmd(String cmd) { try{ string[] cmdList = cmd.Split(null); CommandTo cmdto = null; Parser.Default.ParseArguments <CommandTo>(cmdList).WithParsed <CommandTo>(o => { cmdto = o; }); if (cmdto.udp) { udpSendCmd(cmdto); return(0); } this.sock = new TcpClient(cmdto.to, _port); byte[] btysSend = new byte[] { (byte)NetType.Command }; this.sock.Client.Send(btysSend); this.sock.Client.Send(Encoding.UTF8.GetBytes(cmdto.cmdStr)); // byte[] btysReceive = new byte[1024]; // int resNum = this.sock.Client.Receive(btysReceive); // Console.WriteLine(resNum); return(0); // normal } catch (Exception e) { Console.WriteLine("Send Command failed!" + e); return(1); } }
public int udpSendCmd(CommandTo cmd) { // DatagramSocket ds = new DatagramSocket(); // InetAddress serverIp = InetAddress.getByName(cmd.to); // // this.dos.writeInt(GaiaType.Command.ordinal()); // 0 represent Command; // DatagramPacket dpSent = new DatagramPacket(cmd.cmdStr.getBytes(StandardCharsets.UTF_8),cmd.cmdStr.length(),serverIp,9190); // ds.send(dpSent); return(0); // normal }