Results 1 to 8 of 8

Thread: How to get network/internet speed?

  1. #1
    Join Date
    Oct 2007
    Posts
    39
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Question How to get network/internet speed?

    I have to upload/download the files/data to the server using sockets.
    Based on the internet speed I have to decide between TCP and UDP socket connection to be used for the operations.

    Please help me out as how to get the internet speed?

    Thanks in advance.
    Darshan

  2. #2
    Join Date
    Aug 2009
    Posts
    6
    Qt products
    Platforms
    Unix/X11 Windows

    Default Re: How to get network/internet speed?

    I know there is a lib for this https://github.com/teeks99/speed_check, I think it will help you to figure out your situatuon with this. And this also https://github.com/wardi/speedometer , http://excess.org/speedometer/

  3. #3
    Join Date
    Oct 2007
    Posts
    39
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to get network/internet speed?

    I am looking for a Qt or C++ implementation rather than executing any script.
    Darshan

  4. #4
    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: How to get network/internet speed?

    The only way to check the connection speed is to actually try and transmit something. Just be aware that there may be some traffic management involved and speed for TCP and UDP or even speed of the same protocol but using different ports might be different.
    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.


  5. #5
    Join Date
    Oct 2007
    Posts
    39
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to get network/internet speed?

    Yes.. I have read on some other forums and also have checked the QtNetworkMonitor project.

    After successful connection with the server (TCP/UDP), the file is uploaded and speed is calculated as:

    speed = (bytes of data) / (time elapsed)
    Can you please suggest a way to reach to the max bytes for the connection made with the server? As of now I am more concerned about the TCP connection.
    Darshan

  6. #6
    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: How to get network/internet speed?

    What do you mean by "max bytes for the connection"?
    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.


  7. #7
    Join Date
    Oct 2007
    Posts
    39
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Exclamation Re: How to get network/internet speed?

    I tried sending the packets over the TCP connection say of size 1KB. Below is the sample function

    Qt Code:
    1. void checkBandwidth()
    2. {
    3. QTcpSocket bandWidthSock;
    4. int port = 1000;
    5. bandWidthSock.connectToHost("host", port); //connect to server to check bandwidth
    6.  
    7. if(bandWidthSock.waitForConnected())
    8. {
    9. QTime time;
    10.  
    11. QFile file("dump.txt");
    12. if(!file.open(QFile::ReadOnly))
    13. {
    14. qDebug() << "Unable to read file: " << file.fileName();
    15. return;
    16. }
    17.  
    18. QString strFileData = file.readAll();
    19. file.close();
    20.  
    21. quint64 bytesWritten ;
    22. QString strData;
    23.  
    24. time.start();
    25. qDebug() << "bytesAvailable: " << bandWidthSock.bytesToWrite();
    26.  
    27. while(!bandWidthSock.bytesAvailable())
    28. {
    29. strData += strFileData;
    30. qDebug() << "bytesAvailable: " << bandWidthSock.bytesToWrite() << " writing: " << strData.length();
    31.  
    32. time.restart();
    33. bytesWritten = bandWidthSock.write(strData.toStdString().c_str(), strlen(strData.toStdString().c_str()));
    34. }
    35.  
    36. int uploadTime = time.elapsed();
    37. int speed = (((int)bytesWritten)*(1000 )) / uploadTime;
    38.  
    39. QString strDisplay("bytes written: ");
    40. strDisplay.append(QString::number(bytesWritten));
    41. strDisplay.append("\nupload time: ");
    42. strDisplay.append(QString::number(uploadTime));
    43. strDisplay.append("\nSpeed: ");
    44. strDisplay.append(QString::number(speed));
    45.  
    46. QMessageBox::information(0, "test", strDisplay);
    47.  
    48. }
    49.  
    50. bandWidthSock.disconnectFromHost();
    51. bandWidthSock.close();
    52. }
    To copy to clipboard, switch view to plain text mode 

    I am increasing the data written on the socket if the availableBytes() are 0. But the app goes into the endless loop.
    Please let me know you comments.
    Darshan

  8. #8
    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: How to get network/internet speed?

    bytesAvailable() returns the number of bytes available for reading, thus you always get 0 there.
    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.


Similar Threads

  1. How to speed up the Qt GUI apps launch speed?
    By wshn13 in forum Qt Programming
    Replies: 3
    Last Post: 14th March 2012, 08:37
  2. Using Maps without internet
    By wladek in forum Qt Quick
    Replies: 4
    Last Post: 12th July 2011, 04:34
  3. internet radio
    By Madhumitha in forum Newbie
    Replies: 0
    Last Post: 23rd February 2011, 07:28
  4. How to use a image from internet
    By kellen851105 in forum Qt Programming
    Replies: 1
    Last Post: 4th March 2010, 06:16
  5. Is internet connected
    By bunjee in forum Qt Programming
    Replies: 2
    Last Post: 24th November 2009, 21:22

Tags for this Thread

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.