How to test internet speed (JavaSE)?
Is there a way to test intern开发者_如何学JAVAet speed using Java code?
For instance, like how we actually test with cmd command, ping command.
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());
}
});
精彩评论