[SNMP4J] Problem:Unable to receive a response
Mark Chan
markctl at gmail.com
Wed Jun 22 02:25:02 CEST 2005
Hi all,
Thanks guys got my problem solved. Apparently i left out the listen
function(). However i did realise that i had to call the
snmp.sendPDU(request, target, null, listener); to get a response. The
snmp.send(request, target) did not work...
Is that okay?
Best Regards,
Mark
The sample code that i used is a as follows:
public static void main(String[] args) throws IOException, InterruptedException{
Address targetAddress = GenericAddress.parse("udp:192.168.0.126/161");
DefaultUdpTransportMapping tempUdp = new DefaultUdpTransportMapping();
CommunityTarget target = new CommunityTarget();
target.setCommunity(new OctetString("public"));
target.setAddress(targetAddress);
target.setVersion(SnmpConstants.version1);
target.setRetries(1);
// set timeout to 500 milliseconds -> 2*500ms = 1s total timeout
target.setTimeout(7000);
target.setVersion(SnmpConstants.version1);
Snmp snmp = new Snmp(tempUdp);
tempUdp.listen();
PDU request = new PDU();
request.add(new VariableBinding(new OID(".1.3.6.1.2.1.1.3")));
request.setType(PDU.GETNEXT);
ResponseListener listener = new ResponseListener() {
public void onResponse(ResponseEvent event) {
PDU response = event.getResponse();
PDU request = event.getRequest();
if (response == null) {
System.out.println("Request "+request+" timed out");
}else{
System.out.println("Received response "+response+" on request "+
request);
}
}
};
snmp.sendPDU(request, target, null, listener);
Thread.sleep(15000);
}
More information about the SNMP4J
mailing list