[SNMP4J] The method snmp.send() returns a null ResponseEvent, why?
xsong at profilium.com
xsong at profilium.com
Tue Feb 20 17:44:05 CET 2007
Hi,
I just started to write code for SNMP, I found SNMP4j is very help. The following code trys to send out a TRAP pdu, but it does not work. Debug finds that everythings is find until the snmp.send() is called, the method is supposed to returns a ResponseEvent, but it returns null.
.............
// set up a default SNMP session for UDP and with SNMPv3 support
TransportMapping udpTransport = new DefaultUdpTransportMapping();
Snmp snmp = new Snmp(udpTransport);
USM usm = new USM(SecurityProtocols.getInstance(),
new OctetString(MPv3.createLocalEngineID()), 0);
SecurityModels.getInstance().addSecurityModel(usm);
// set up the target
Address targetAddress = GenericAddress.parse("udp:192.168.1.156/162");
CommunityTarget target = new CommunityTarget();
target.setCommunity(new OctetString("public"));
target.setAddress(targetAddress);
target.setRetries(2);
target.setTimeout(1500);
target.setVersion(SnmpConstants.version2c);
// create a SNMP trap PDU
PDU trapPdu = new PDU();
trapPdu.add(new VariableBinding(new OID("1.3.6.1.2.1.1.1"),
new OctetString("Alarm 1")));
trapPdu.add(new VariableBinding(new OID("1.3.6.1.2.1.2.1"),
new OctetString("Alarm 2")));
trapPdu.setType(PDU.TRAP);
// sending out the SNMP trap PDU synchronously
ResponseEvent response = snmp.send(trapPdu, target);
if (response.getResponse() == null) {
System.out.println("sending request timed out");
}
else {
System.out.println("Received response from "
+response.getPeerAddress());
// dump response PDU
System.out.println(response.getResponse().toString());
};
...............
I traced the inside steps of the snmp.send(), it seems everything is fine there: the pdu message is encoded, written to the buffer, and sent out a socket. Could anyone tell me what is wrong with my code?
Thanks...
Xinxin
More information about the SNMP4J
mailing list