//得到系统时间
SYSTEMTIME   systime;   
GetLocalTime(&systime); 
CString dwStart;
dwStart.Format("%d%d%d%d ",systime.wHour,systime.wMinute,systime.wSecond,systime.wMilliseconds);//每次读1024字节
num=myFile.Read(m_buf, SIZEFILE);
if(num==0) break;
//发送1024字节
end = send(pDlg->sockb,m_buf,num,0);

Sleep(1);//把这一行删掉程序运行时崩溃

//得到系统时间
CString dwEnd;
GetLocalTime(&systime); 
dwEnd.Format("%d%d%d%d ",systime.wHour,systime.wMinute,systime.wSecond,systime.wMilliseconds);
 //计算每秒的发送字节
int a=atol(dwStart);
int b=atol(dwEnd);
int c=1000/(b-a);
CString strTimeint;
strTimeint.Format("每秒传送 %dKB",c);
//发给全局变量
strName=strTimeint;请专家帮忙给更正一下
谢谢了

解决方案 »

  1.   

    一次发送不等于速率。网络的单次报文的速度不代表它自己的速度,因为网络报文发送速度有一定波动性,你必须统计很多报文才能计算平均速度。而且,send成功不代表数据真发送出去了再说,时间/小时/分钟都是60进制,你打印到str在atol明显错误,干吗不直接根据时间计算,而用字符串转?
      

  2.   

    首先,你要清楚接收的数据单位为BYTE
    用1024除以接收数据之后的时间减去接受数据之前的时间差,得到的商乘以1000
    因为时间单位为毫秒
      

  3.   

    我找到原因了就是不知道怎么解决
    因为下面的程序用了0毫秒的时间
    //每次读1024字节 
    num=myFile.Read(m_buf,   SIZEFILE); 
    if(num==0)   break; 
    //发送1024字节 
    end   =   send(pDlg-> sockb,m_buf,num,0); 1000/0/程序崩溃
    请问如何解决?