java - 测量使用 Java 套接字传输文件时使用的带宽

标签 java file rmi transfer

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

最佳答案

这可以通过装饰套接字的输入和输出流来实现。

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

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 .

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

关于java - 测量使用 Java 套接字传输文件时使用的带宽,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8440787/

相关文章:

c - 读取文件错误 C_language

c++ - 如何在 C++ 中进行文件检查

Java RMI Netbeans 包

javascript - 如何根据 servlet 响应在 html 中显示 "login failed"消息

java - 停止 Java Quartz 调度程序

java - Clientrequestfilter 与 Containerrequestfilter

java - 如何在文件中搜索字符串

Java RMI - 注册表绑定(bind)调用导致 NoSuchObjectException

java - 如何使用java RMI转发消息?

java - 使用 IOUtils 和 ImageIO 写入图像文件有什么区别