【问题标题】:Measure bandwith used in transfering files with java sockets测量使用 java 套接字传输文件时使用的带宽
【发布时间】:2011-12-09 03:43:18
【问题描述】:

有人知道怎么做吗?使用 java 套接字

【问题讨论】:

  • 如何定义“带宽浪费”?

标签: java file rmi transfer


【解决方案1】:

这可以通过修饰socket的输入输出流来实现。

所以它可能看起来像这样:

class SocketWrapper extends Socket {
    private CountingInputStream input;

    @Override
    public InputStream getInputStream() throws IOException {
        if (input == null) {
            input = new CountingInputStream(super.getInputStream());
        }

        return input;
    }

    public int getInputCounter() {
        return input.getCounter();
    }

    // other stuff like getOutputStream
}

class CountingInputStream extends InputStream {
    private final InputStream inputStream;

    public CountingInputStream(InputStream inputStream) {
        this.inputStream = inputStream;
    }

    private int counter = 0;

    public int getCounter() {
        return counter;
    }

    @Override
    public int read() throws IOException {
        counter++;
        return inputStream.read();
    }

    // other methods
}

也可以看看herehere

最后,如果您只想知道流量,您可以使用嗅探器。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-04
    • 1970-01-01
    相关资源
    最近更新 更多