怎么得到传送速度,各位大哥举个简单列子啊。

解决方案 »

  1.   

    自己编程实现吧计算累积发送的大小,除以时间,得出速度,如果太快,则在发包前 停顿(Sleep(ms)) 
    一下。这个 停顿 的时间长度可以由你计算出来的速度与上限速度的关系自行计算。
      

  2.   

    自行计算每秒检查数据流量,这就是速度的
    过一段时间,例如1分钟再计算,这就是所谓的"平均速度",是估算值来的_____________________
    http://lysoft.7u7.net
      

  3.   

    function TFrmDFTD.fGetFile:Boolean;
    var Geting:Boolean;
        aITotal,aIRdCnt,aIFSize,aIDSz:Integer;
        aITry,aIx,aIdx,aIdy:Integer;
        aStrRcv,aStrCmd:String;
        aSSIZ,aSSUM:String;
        Buf:Pointer;
        aByt:Byte;
        AFStream:TFileStream;
        T1,T2,Td:TTime;
        aBtl,aBtl0:Real;
        aHH,aMM,aSS,aZZ:Word;
        CmdChr:array[0..63] of Char;
    begin
      result:=False;
        Geting:=True;
        aBtl0:=0;
        LbBtl.Caption:='0.00';
        if Geting then
        begin
          AFStream:=TFileStream.Create(aStrTarF,fmCreate);
          GetMem(Buf,1024);
          try
            CltSkt1.OnRead :=nil;
            vBusy:=True;
            aITotal:=0;
            aDwSum:=0;
            aITry:=1;
            PgBr.Visible:=True;
            PgBr.Max:=aIFSize;
            T1:=Time;
            while Geting do
            begin
              if gBeStop then Break;
              if vHasSktErr then Exit;
              Application.ProcessMessages;
              if not CltSkt1.Socket.Connected then
              begin
                Memo1.lines.Add('Socket连接已被中断。');
                Break;
              end;
              aIRdCnt:=CltSkt1.Socket.ReceiveBuf(Buf^,1024);
              LbBts.Caption:=IntToStr(aIRdCnt);
              LbBts.Update;
              if aIRdCnt>0 then
              begin
                T2:=Time;
                Td:=T2-T1;
                DecodeTime(Td,aHH,aMM,aSS,aZZ);
                Td:=aHH*3600+aMM*60+aSS+aZZ /1000;
                if Td>0 then
                begin
                  aBtl:=(aITotal/1024) / Td;
                  aBtl0:=(aBtl0+aBtl)/2;
                  aStrCmd:=FormatFloat(' 0.00',aBtl0);
                  LbBtl.Caption:='  '+aStrCmd;
                  LbBtl.Update;
                end;
                  if aITotal+aIRdCnt>aIFSize then
                    aIDSz:=aIFSize-aITotal
                  else
                    aIDSz:=aIRdCnt;
                  AFStream.WriteBuffer(Buf^,aIDSz);
                  aITotal:=aITotal+aIDSz;
                  if PgBr.Position<>aITotal then
                    PgBr.Position :=aITotal;
                if aITotal>=aIFSize then
                begin
                   Geting:=False;
                   Break;
                end else
                begin
                end;
              end;
            end;
          finally
            FreeMem(Buf,1024);
            AFStream.Free;
            if Result then
            begin
            end else
            begin
              Memo1.lines.Add(xStrTBN+'下载未完成.');
            end;
            vBusy:=False;
            CltSkt1.OnRead :=CltSkt1Read;
            PgBr.Visible:=False;
          end;
        end;
      end;
    end;