Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to test internet speed (JavaSE)?

Tags:

java

Is there a way to test internet speed using Java code?

For instance, like how we actually test with cmd command, ping command.

like image 323
Mr CooL Avatar asked Mar 22 '10 07:03

Mr CooL


People also ask

How do you perform a speed test?

The quickest way to run an accurate, consistent and reliable speed test is to go to Speedtest.net and download the designated app for the device you want to test. Speedtest.net is a free service run by Ookla that has native apps for pretty much any platform, including iOS, Android, Windows and macOS.


2 Answers

Look here on howto ping in java:

http://blog.taragana.com/index.php/archive/how-to-do-icmp-ping-in-java-jdk-15-and-above/

As the other dude said it is not a perfect solution I looked into our codebase because I knew we do something with ICMP packets here's what we use:

http://www.savarese.com/software/rocksaw/

It does mean you'll have to compile a bit of JNI C to have access to a rawsocket (win32 and linux) are supported.

But you should look into a few more things to get a propper idea of internet speed:

  • check the amount of connections possible in 10 secs
  • check how long it takes to download a 5MB file
  • check how long it takes to upload a 5MB file

that in combination with a few pings should give you quite a good impression of bandwidth and latency

like image 79
albertjan Avatar answered Sep 20 '22 22:09

albertjan


use JSpeedTest Library

SpeedTestSocket speedTestSocket = new SpeedTestSocket();

// add a listener to wait for speedtest completion and progress
speedTestSocket.addSpeedTestListener(new ISpeedTestListener() {

    @Override
    public void onCompletion(SpeedTestReport report) {
        // called when download/upload is complete
        System.out.println("[COMPLETED] rate in octet/s : " + report.getTransferRateOctet());
        System.out.println("[COMPLETED] rate in bit/s   : " + report.getTransferRateBit());
    }

    @Override
    public void onError(SpeedTestError speedTestError, String errorMessage) {
         // called when a download/upload error occur
    }

    @Override
    public void onProgress(float percent, SpeedTestReport report) {
        // called to notify download/upload progress
        System.out.println("[PROGRESS] progress : " + percent + "%");
        System.out.println("[PROGRESS] rate in octet/s : " + report.getTransferRateOctet());
        System.out.println("[PROGRESS] rate in bit/s   : " + report.getTransferRateBit());
    }
});
like image 1
Favas kottayil Avatar answered Oct 10 '22 11:10

Favas kottayil