开发者

Calculating bandwidth speed of data sent/received over a socket?

Does anyone have any tips on how to calculate the bandwidth usage of a socket?

For example, as I send data over a socket to the server I am connected to, I want to show the Kb/s that is being sent.

Google search didn't reveal anything useful. Maybe I'm searc开发者_运维问答hing the wrong terms.


The best you're probably going to be able to easily do is to record when you start writing and then count bytes you've successfully sent to the Socket.getOutputStream.write() method. For a small amount of data, that will be very inaccurate as it's just filling up the OS's transmission buffer which will initially take bytes much faster than it actually sends them.

It should amortize to essentially the correct rate over a fairly large amount of data, however.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜