download/upload speed calculations

This is a discussion on download/upload speed calculations within the Networking/Device Communication forums, part of the General Programming Boards category; Hi, Im trying to calculate download/upload speed based on total data downloaded/uploaded. The problem with my current method is that ...

  1. #1
    Registered User
    Join Date
    Aug 2003
    Posts
    288

    download/upload speed calculations

    Hi,

    Im trying to calculate download/upload speed based on total data downloaded/uploaded.

    The problem with my current method is that it sometimes displays a really large value. Heres the code im using, its called after every send/recv, xBandwidthInfo is a global struct used to keep track of the totals/rates.

    Code:
    void CalculateRates()
    {
    	xBandwidthInfo *m_pInfo = (xBandwidthInfo *)lpvMem;
    
    	int nTimeDelta = timeGetTime() - m_pInfo->nLastTime;
    
    	if (nTimeDelta == 0)
    		nTimeDelta = 1;
    
    	if (abs(nTimeDelta) >= 1000) // reset every second
    	{
    		m_pInfo->nLastDownload = m_pInfo->nTotalDownload;
    		m_pInfo->nLastUpload = m_pInfo->nTotalUpload;
    		m_pInfo->nLastTime = timeGetTime();
    	}
    
    	uint nCurrentDownload = m_pInfo->nTotalDownload - m_pInfo->nLastDownload;
    	uint nCurrentUpload = m_pInfo->nTotalUpload - m_pInfo->nLastUpload;
    
    	float fTime = 1000.0f / nTimeDelta;
    	fTime = abs(fTime);
    
    	m_pInfo->fDownloadRate = (float)nCurrentDownload * fTime;
    	m_pInfo->fUploadRate = (float)nCurrentUpload * fTime;
    }

  2. #2
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    reset current download/upload zero

    x = current - last (unsigned int)

    possible?

    Kuphryn

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. I am very new . . . :(
    By Eternalglory47 in forum C++ Programming
    Replies: 6
    Last Post: 09-05-2008, 12:29 PM
  2. Flight Simulator Wind Speed!!
    By Dilmerv in forum C++ Programming
    Replies: 6
    Last Post: 03-20-2006, 12:40 AM
  3. Replies: 6
    Last Post: 01-08-2006, 02:49 PM
  4. increased net speed
    By PING in forum A Brief History of Cprogramming.com
    Replies: 20
    Last Post: 03-29-2005, 07:05 AM
  5. VB Speed compared to VC++ Speed.
    By Xei in forum C++ Programming
    Replies: 6
    Last Post: 05-19-2002, 05:01 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21