2
누구든지이 작업을 수행하는 방법을 알고 있습니까? 자바 소켓 사용자바 소켓을 사용하여 파일을 전송하는 데 사용되는 대역폭 측정
누구든지이 작업을 수행하는 방법을 알고 있습니까? 자바 소켓 사용자바 소켓을 사용하여 파일을 전송하는 데 사용되는 대역폭 측정
소켓의 입력 스트림과 출력 스트림을 꾸미면이 작업을 수행 할 수 있습니다.
그래서 다음과 같습니다
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
}
또한보고
here 및
here 있습니다.
마지막으로 트래픽 양을 알고 싶다면 스니퍼를 사용할 수 있습니다.
예제 코드와 사용 된 속도를 측정하는 방법을 제공하므로 this accepted answer을 참조하십시오.
"대역폭 낭비"는 어떻게 정의합니까? –
used * 죄송합니다. 내 잘못 –
updated title ... – akf