Is there a way to test internet speed using Java code?
For instance, like how we actually test with cmd command, ping command.
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.
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:
that in combination with a few pings should give you quite a good impression of bandwidth and latency
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());
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With