[SNMP4J] The method snmp.send() returns a null ResponseEvent, why?
Frank Fock
fock at agentpp.com
Tue Feb 20 20:57:16 CET 2007
Hi,
A TRAP PDU is not confirmed, so there will be
never a response and therefore the response is
null and everything is fine as it should be.
Best regards,
Frank
xsong at profilium.com wrote:
> 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
--
AGENT++
http://www.agentpp.com
http://www.mibexplorer.com
http://www.mibdesigner.com
More information about the SNMP4J
mailing list