I know the answer, but how to deal with it? RE: [SNMP4J] The method snmp.send() returns a null ResponseEvent,

xsong at profilium.com xsong at profilium.com
Tue Feb 20 19:10:28 CET 2007


Hi,

I kind of found the answer after I checked the source code of the class SNMP. Because trapPdu is not a confirmed PDU (PDU REPORT, RESPONSE, TRAP, V1TRAP are all non-confirmed pdus), the SNMP.send() returns NULL. That is why the returned responseEvent is NULL.  But how to deal with it?  I should not expect to get any response when sending REPORT, RESPONSE, TRAP, V1TRAP PDUs?

Thanks...

Xinxin


>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
>_______________________________________________
>SNMP4J mailing list
>SNMP4J at agentpp.org
>http://lists.agentpp.org/mailman/listinfo/snmp4j



More information about the SNMP4J mailing list