2011-12-09 2 views

답변

1

소켓의 입력 스트림과 출력 스트림을 꾸미면이 작업을 수행 할 수 있습니다.

그래서 다음과 같습니다

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 있습니다.

마지막으로 트래픽 양을 알고 싶다면 스니퍼를 사용할 수 있습니다.

0

예제 코드와 사용 된 속도를 측정하는 방법을 제공하므로 this accepted answer을 참조하십시오.

관련 문제