Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/329.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java中使用的带宽计算公式_Java_Formula_Bandwidth - Fatal编程技术网

Java中使用的带宽计算公式

Java中使用的带宽计算公式,java,formula,bandwidth,Java,Formula,Bandwidth,我环顾了一下四周,似乎找不到适合我需要的好配方。对于与应用程序的单个连接,我有以下值 long elapsedTimeSeconds = (System.currentTimeMillis() - client.getCreationTime()) / 1000; long totalBytesRead = conn.getReadBytes(); long totalBytesWritten = conn.getWrittenBytes(); 我想计算在经过的时间段内使用的带宽量(读写),单

我环顾了一下四周,似乎找不到适合我需要的好配方。对于与应用程序的单个连接,我有以下值

long elapsedTimeSeconds = (System.currentTimeMillis() - client.getCreationTime()) / 1000;
long totalBytesRead = conn.getReadBytes();
long totalBytesWritten = conn.getWrittenBytes();
我想计算在经过的时间段内使用的带宽量(读写),单位为Kbps

这是单独计算的正确公式吗

long readBandwidthUsed = (totalBytesRead / 1024) / elapsedTimeSeconds;

我最终使用了这个公式:

long bandwidthUsed = (totalBytes / 1024) / elapsedTimeSeconds; 使用的长带宽=(totalBytes/1024)/elapsedTimeSeconds;
你能提供更多的信息吗,比如“conn”和“client”是什么?当然,但它们“是什么”与答案无关。客户端是Flash播放器的表示,而conn是RTMPConnection实例。长值在这里很重要。你的问题是什么?(我没有看到一个问号,你的公式也没有任何问题…@meriton公式应该先加上读写的总字节数,但除此之外,我也没有。这是我一直在寻找的答案,基本上是正确的公式吗?我只是从我读的东西中猜出来的。