Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
PDU pdu = new PDU();
pdu.add(new VariableBinding(new OID(new int[] {1,3,6,1,2,1,1,1})));
pdu.add(new VariableBinding(new OID(new int[] {1,3,6,1,2,1,1,2})));
pdu.setType(PDU.GETNEXT);

...

Send the message asynchronously
Code Block
class MyResponseListener implements ResponseListener {
  boolean finished = false;
  public void onResponse(ResponseEvent event) {
     System.out.println("Received response PDU is: "+event.getResponse());
     if (event.getResponse() == null) {
       finished = true;
       listener.notify();
     }
   }

   public boolean isFinished() {
     return finished;
   }
 };

 MyResponseListener listener = new MyResponseListener() { 
 snmp.sendPDU(pdu, target, null, listener);
 try {
   while (!listener.isFinished()) {
     listener.wait(target.getTimeout()*2);
   }
 } catch (InterruptedException iex) {
     System.out.println("Request cancelled: "+iex.getMessage());
 }