I am building an application in Java where I need to know the download/upload speed as we get in https://speedtest.net kind of sites. Are there any APIs/java inbuilt methods using which I can get the speeds. Thanks!
I am building an application in Java where I need to know the download/upload speed as we get in https://speedtest.net kind of sites. Are there any APIs/java inbuilt methods using which I can get the speeds. Thanks!
You can use JSpeedTest:
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 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 bit/s : " + report.getTransferRateBit());
}
});
speedTestSocket.startDownload("http://ipv4.ikoula.testdebit.info/1M.iso");
speedTestSocket.startUpload("http://ipv4.ikoula.testdebit.info/", 1000000);
speedTestSocket.startFixedDownload("http://ipv4.ikoula.testdebit.info/100M.iso", 10000);
speedTestSocket.startFixedUpload("http://ipv4.ikoula.testdebit.info/", 10000000, 10000);
Sample output:
[PROGRESS] progress : 0.1223%
[PROGRESS] rate in bit/s : 4253913.0432
[PROGRESS] progress : 1.2903%
[PROGRESS] rate in bit/s : 18768000.0000
[PROGRESS] progress : 1.4363%
[PROGRESS] rate in bit/s : 19150666.6664
.
.
.
[PROGRESS] progress : 98.6723%
[PROGRESS] rate in bit/s : 11584655.1216
[PROGRESS] progress : 99.2563%
[PROGRESS] rate in bit/s : 11651509.9048
[PROGRESS] progress : 100.0%
[PROGRESS] rate in bit/s : 11694196.7552
[COMPLETED] rate in bit/s : 11690778.8984
Maven dependency:
<!-- https://mvnrepository.com/artifact/fr.bmartel/jspeedtest -->
<dependency>
<groupId>fr.bmartel</groupId>
<artifactId>jspeedtest</artifactId>
<version>1.32.1</version>
</dependency>
I don't think there is ready made API for this.
The setup for this solution is a client-server design
TYou could have the client do this calculation periodically too and show the speed experienced by the client on each update event.
Hope this helps. :)