开发者

How to test internet speed (JavaSE)?

开发者 https://www.devze.com 2022-12-23 22:23 出处:网络
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

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());
    }
});
0

精彩评论

暂无评论...
验证码 换一张
取 消