[SNMP4J] Asynchronous Request Not Working with SNMP v3
lalit patel
lalitkpatel82 at gmail.com
Tue Mar 25 13:53:34 CET 2008
Hi
I wonder why the following code is not working?
........
.......
try{
TransportMapping transport = new DefaultUdpTransportMapping();
Snmp snmp= new Snmp(transport);
USM usm = new USM(SecurityProtocols.getInstance(),
new OctetString(MPv3.createLocalEngineID()), 0);
SecurityModels.getInstance().addSecurityModel(usm);
//transport.listen();
// add user to the USM
snmp.getUSM().addUser(new OctetString(AdminName),
new UsmUser(new OctetString(AdminName),
AuthMD5.ID,
new OctetString(Password),
PrivDES.ID,
new OctetString(Password)));
// create the target
UserTarget target[] = new UserTarget[NoOfSite];
for(int i=0;i<NoOfSite;i++)
{
target[i] = new UserTarget();
}
for(int i=0;i<NoOfSite;i++)
{
target[i].setAddress(targetAddress[i]);
target[i].setRetries(2);
target[i].setTimeout(5000);
target[i].setVersion(SnmpConstants.version3);
target[i].setSecurityLevel(SecurityLevel.AUTH_PRIV);
target[i].setSecurityName(new OctetString(AdminName));
}
ScopedPDU pdu = new ScopedPDU();
pdu.add(new VariableBinding(new OID("1.3.6.1.2.1.1.3")));//
sysuptime
pdu.setType(PDU.GET);
//transport.listen();
snmp.listen();
ResponseListener listener = new ResponseListener() {
public void onResponse(ResponseEvent event) {
//((Snmp)event.getSource()).cancel(event.getRequest(), this);
if (event.getResponse() == null) {
//System.out.println("Request "+request+" timed out");
System.out.println("Sorry Request Time out");
}
else {
System.out.println("Hello lalit you got response!");
//System.out.println("Received response "+response+"\n on
request "+request);
System.out.println(event.getResponse().toString());
}
}
};
for(int i=0;i<NoOfSite;i++)
{
snmp.send(pdu, target[i], null, listener); //send all request
}
}
catch (IOException e) {
System.err.println("Caught IOException: "+ e.getMessage());
}
}
}
Any suggestion ??
thanks
lalit
More information about the SNMP4J
mailing list