Пример #1
0
        public bool IsAutoCmd(ITcpCommand tcpCmd)
        {
            var getCmd = tcpCmd.GetCmdCode();

            if (getCmd == CmdCode.Heart)
            {
                return(true);
            }
            return(false);
        }
Пример #2
0
            //发送一条命令
            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());
            }
Пример #3
0
 public void FreshPacket(ITcpCommand tcpCmd)
 {
     base._Pack_Data = null;     //直接使用命令数据而不是数组
     if (tcpCmd.GetNetStream() == null)
     {
         base._Pack_Length = (uint)(_minSize);
     }
     else
     {
         base._Pack_Length = (uint)(_minSize + tcpCmd.GetNetStream().Length);
     }
     base._Pack_CmdID   = _cmdIdCount++;
     this._Pack_CmdCode = tcpCmd.GetCmdCode();
     this._tcpCmd       = tcpCmd;
     InitNetStream();
 }
Пример #4
0
 public void ProcAutoCmd(ITcpCommand tcpCmd)
 {
     MainForm.SetOutPutText(String.Format("TcpAutoCmdProcer_Log:cmdCode = {0}", tcpCmd.GetCmdCode().ToString()));
 }