gpt4 book ai didi

java - 如何测试互联网速度(JavaSE)?

转载 作者:搜寻专家 更新时间:2023-10-30 21:12:13 25 4
gpt4 key购买 nike

有没有办法使用 Java 代码测试互联网速度?

比如我们实际是如何用cmd命令、ping命令进行测试的。

最佳答案

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

关于java - 如何测试互联网速度(JavaSE)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2490552/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com