Results 1 to 3 of 3

Thread: QTCPSocket - Download Speed

  1. #1
    Join Date
    Jun 2008
    Location
    UK
    Posts
    35
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QTCPSocket - Download Speed

    Hi,

    I'm wondering if someone could kindly help me with a high level design for how to download through a QTCPSocket, in order to obtain reliable downstream speeds in real time.

    Its a custom protocol, but basically once I issue a request for some data, I need to keep downloading until I receive the terminating bytes <CR><LF>.<CR><LF>

    Here is my current thinking:

    - Request data download
    - Record current timestamp
    - Read X bytes through the socket
    - Record new timestamp, compute time difference and work out speed for the transfer of X bytes, signal this out...
    - Repeat until terminating bytes: <CR><LF>.<CR><LF> are detected.

    Does this seem like a solid approach to the problem? If so, my question is how many bytes should I read per cycle (size of X)?

    Baring in mind the transfer size could be a few bytes to many megabytes, what transfer cycle size is good for best performance, and also enough to calculate reliable, real-time download speeds?

    I guess also I would need to record the last cycles data in case half of the terminating bytes came through at the end of the last cycle?

    Many thanks for any help,

    Jack

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTCPSocket - Download Speed

    You should recalculate the speed each time you receive new data to provide better and better approximation of the average speed. How to approximate is up to you - you can either use the whole download history or only the recent part (i.e. last 10s of download). To store the statistics you can use a simple QMap<QTime,int> to store amounts of data downloaded during subsequent periods of time.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jun 2008
    Location
    UK
    Posts
    35
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QTCPSocket - Download Speed

    Thanks that makes sense, will go down that route.
    Last edited by tntcoda; 24th May 2009 at 16:15. Reason: updated contents

Similar Threads

  1. Reimplement QTcpSocket to limit download speed ???
    By THRESHE in forum Qt Programming
    Replies: 3
    Last Post: 29th November 2010, 14:30
  2. How to limit download speed with QHttp ?
    By THRESHE in forum Qt Programming
    Replies: 6
    Last Post: 25th November 2010, 11:55
  3. Challenging QTcpSocket reliability problem
    By Raccoon29 in forum Qt Programming
    Replies: 3
    Last Post: 13th January 2009, 10:38
  4. Strange QTcpSocket behavior (debugged with Ethereal)
    By mdecandia in forum Qt Programming
    Replies: 23
    Last Post: 28th May 2007, 20:44
  5. QTcpSocket speed problem
    By benelgiac in forum Qt Programming
    Replies: 4
    Last Post: 1st May 2007, 13:50

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.