Speed Test client library for Java/Android with HTTP & FTP support
- speed test download
- speed test upload
- download / upload progress monitoring
- configurable hostname / port / uri (username & password for FTP)
- configurable socket timeout and chunk size
- configure upload file storage
Check a non-exhaustive list of compatible speed test server.
- with Gradle, from jcenter or mavenCentral :
compile 'fr.bmartel:jspeedtest:1.31.2'
- setup a speed test listener to monitor progress, completion and error catch :
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());
}
});
- HTTP download 1Mo from
2.testdebit.info
speedTestSocket.startDownload("http://2.testdebit.info/fichiers/1Mo.dat");
- FTP download 1Mo from
speedtest.tele2.net
speedTestSocket.startDownload("ftp://speedtest.tele2.net/1MB.zip");
- FTP download 1Mo from
ftp.otenet.gr
with credentials (username/password), default is anonymous/no password
speedTestSocket.startDownload("ftp://speedtest:[email protected]/test1Mb.db");
- HTTP upload 1Mo to
2.testdebit.info
speedTestSocket.startUpload("http://2.testdebit.info/", 1000000);
- FTP upload a 1Mo file to
speedtest.tele2.net
String fileName = SpeedTestUtils.generateFileName() + ".txt";
speedTestSocket.startUpload("ftp://speedtest.tele2.net/upload/" + fileName, 1000000);
Download during a fixed duration. Download will be stopped when the max duration is reached.
- HTTP download for 10s max, a 100 Mo file from
2.testdebit.info
speedTestSocket.startFixedDownload("http://2.testdebit.info/fichiers/100Mo.dat", 10000);
- FTP download for 10s max, a 100 Mo file from
speedtest.tele2.net
speedTestSocket.startFixedDownload("ftp://speedtest.tele2.net/100MB.zip");
Upload during a fixed duration. Upload will be stopped when the max duration is reached
- HTTP upload for 10s max, a 10Mo file to
2.testdebit.info
speedTestSocket.startFixedUpload("http://2.testdebit.info/", 10000000, 10000);
- FTP upload for 10s max, a 10Mo file to
speedtest.tele2.net
String fileName = SpeedTestUtils.generateFileName() + ".txt";
speedTestSocket.startFixedUpload("ftp://speedtest.tele2.net/upload/" + fileName, 10000000, 10000);
You can define your own report interval (interval between each onDownloadProgress
& onUploadProgress
) in milliseconds.
- HTTP download with download reports each 1.5 seconds
speedTestSocket.startDownload("http://2.testdebit.info/fichiers/1Mo.dat", 1500);
- FTP download with download reports each 1.5 seconds
speedTestSocket.startDownload("ftp://speedtest.tele2.net/1MB.zip", 1500);
- HTTP upload with upload reports each 1.5 seconds
speedTestSocket.startUpload("http://2.testdebit.info/", 10000000, 1500);
- FTP upload with upload reports each 1.5 seconds
String fileName = SpeedTestUtils.generateFileName() + ".txt";
speedTestSocket.startUpload("ftp://speedtest.tele2.net/upload/" + fileName, 10000000, 1500);
speedTestSocket.setProxyServer("http://216.56.48.118:9000");
default proxy server port is 8080
You can chain multiple download/upload requests during a fixed duration. This way, there will be as much download/upload request until the end of the period
- download repeat
The following will download regularly for 20 seconds a file of 1Mo with download report each 2 seconds. Download reports will appear in onReport
callback of IRepeatListener
instead of onDownloadProgress
:
speedTestSocket.startDownloadRepeat("http://2.testdebit.info/fichiers/1Mo.dat",
20000, 2000, new
IRepeatListener() {
@Override
public void onCompletion(final SpeedTestReport report) {
// called when repeat task is finished
}
@Override
public void onReport(final SpeedTestReport report) {
// called when a download report is dispatched
}
});
- upload repeat
The following will upload regularly for 20 seconds a file of 1Mo with download report each 2 seconds. Upload reports will appear in onReport
callback of IRepeatListener
instead of onUploadProgress
:
speedTestSocket.startUploadRepeat("http://2.testdebit.info/", 1000000
20000, 2000, new
IRepeatListener() {
@Override
public void onCompletion(final SpeedTestReport report) {
// called when repeat task is finished
}
@Override
public void onReport(final SpeedTestReport report) {
// called when an upload report is dispatched
}
});
- retrieve current download report :
SpeedTestReport getLiveReport()
- retrieve current upload report :
SpeedTestReport getLiveReport()
Setup time is the amount of time in milliseconds from which speed test will be calculated :
The following will set the setup time to 5 seconds which mean, the speed rate will begin to be computed 5 seconds after the speed test start :
- download
speedTestSocket.setDownloadSetupTime(5000);
- upload
speedTestSocket.setUploadSetupTime(5000);
By default, data to be uploaded is stored in RAM, for large data it is recommended to used file storage :
speedTestSocket.setUploadStorageType(UploadStorageType.FILE_STORAGE);
It will create a temporary file containing random data. File will be deleted automatically at the end of the upload.
speedTestSocket.setUploadChunkSize(65535);
You can set download/upload socket timeout in milliseconds :
speedTestSocket.setSocketTimeout(5000);
These settings are used to alter transfer rate float rounding / scale :
- set RoundingMode :
speedTestSocket.setDefaultRoundingMode(RoundingMode.HALF_EVEN);
Default RoundingMode
used for transfer rate calculation is HALF_EVEN
. It can be override with :
- set Scale :
speedTestSocket.setDefaultScale(4);
Default scale used for transfer rate calculation is 4
- add Internet permission to manifest :
<uses-permission android:name="android.permission.INTERNET" />
- use an
AsyncTask
to run your speed test :
public class SpeedTestTask extends AsyncTask<Void, Void, String> {
@Override
protected String doInBackground(Void... params) {
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 finished
Log.v("speedtest", "[COMPLETED] rate in octet/s : " + report.getTransferRateOctet());
Log.v("speedtest", "[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
Log.v("speedtest", "[PROGRESS] progress : " + percent + "%");
Log.v("speedtest", "[PROGRESS] rate in octet/s : " + report.getTransferRateOctet());
Log.v("speedtest", "[PROGRESS] rate in bit/s : " + report.getTransferRateBit());
}
});
speedTestSocket.startDownload("http://2.testdebit.info/fichiers/1Mo.dat");
return null;
}
}
Execute it with : new SpeedTestTask().execute();
All following examples use speed test server 1.testdebit.info
for HTTP and speedtest.tele2.net
for FTP
- HTTP download (1Mo)
./gradlew downloadFile
- HTTP upload (1Mo)
./gradlew uploadFile
- FTP download (1Mo)
./gradlew downloadFTP
- FTP upload (1Mo)
./gradlew uploadFTP
- HTTP download (1Mo) through proxy server 216.56.48.118:9000
./gradlew downloadFileProxy
- download during a fixed duration (size: 100Mo, duration: 15s, report interval: 1s)
./gradlew fixedDownload
- upload during a fixed duration (size: 100Mo, duration: 15s, report interval: 1s)
./gradlew fixedUpload
- download repeatedly a file during a fixed duration (size:10Mo, duration 11s, report interval: 1s)
./gradlew repeatDownload
- upload repeatedly a file during a fixed duration (size:1Mo, duration 11s, report interval: 1s)
./gradlew repeatUpload
- successive 2 x (download + upload) repeatedly a file during a fixed duration (1 download size:1Mo, duration 3s, report interval: 1s following by 1 upload size:1Mo, duration 3s, report interval: 1s)
./gradlew repeatChain
It's important to choose an adequate speed test server depending on latency/jitter. This library is not responsible for the speed test server choice.
Note that this library :
- doesn't adjust the chunk size depending on the connection speed either
- doesn't provide pre-estimation of the connection speed based on small chunk sent to/from server
- doesn't detect anomaly either (for instance taking away X% slowest chunk and X% fastest chunk downloaded)
This library does provide an average of transfer rate for all individual chunks read/written for download/upload.
The 2 following links describe the process of speedtest.net :
- http://www.ookla.com/support/a21110547/what-is-the-test-flow-and-methodology-for-the-speedtest
- https://support.speedtest.net/hc/en-us/articles/203845400-How-does-the-test-itself-work-How-is-the-result-calculated-
JRE 1.7 compliant
- build without test :
./gradlew clean build -x test
- build with test :
./gradlew clean build
- run specific test
./gradlew test --tests "fr.bmartel.speedtest.test.SpeedTestFunctionalTest"
The MIT License (MIT) Copyright (c) 2016-2017 Bertrand Martel