//发送一条命令 public void SendOneCmd(ITcpCommand tcpCmd) { int oneSendSizeMax = 1024; //每次发送的最大大小 int processCount = 1; //过程计数,1个单位表示10% byte[] sendBuf = new byte[oneSendSizeMax]; _sendPacket.FreshPacket(tcpCmd); var packetStream = _sendPacket.GetNetStream(); var netStream = _client.GetStream(); //记录该条发送的命令号与命令码的绑定 _CmdIdToCodeDir.Add(_sendPacket.GetCurrentCmdId(), tcpCmd.GetCmdCode()); MainForm.SetOutPutText(String.Format("SendOneCmd:start to send:cmd={0},size={1}", tcpCmd.GetCmdCode(), packetStream.Length)); while (true) { //发送数据 int retSize = packetStream.Read(sendBuf, 0, oneSendSizeMax); if (retSize == 0) { break; } netStream.Write(sendBuf, 0, retSize); //打印传输的进度 if (tcpCmd.GetCmdCode() == CmdCode.UpLoadApp) { if (packetStream.Position == (packetStream.Length / 1024) * processCount / 10 * 1024) { MainForm.SetOutPutText(string.Format("SendOneCmd:process {0}%", processCount * 10)); processCount++; } } } MainForm.SetOutPutText("SendOneCmd:send over"); //MainForm.SetOutPutText(_sendPacket.ToString()); }