[SNMP4J] SENDING TRAPS
Frank Fock
fock at agentpp.com
Wed Apr 16 01:36:45 CEST 2008
Hi,
Call snmp.listen() before you send the request,
otherwise you are not listening for a response
and won't get any.
Best regards,
Frank
snmp girl wrote:
> Hello,
>
> I am using the snmp4j api for my programme to use it in order to send traps
> from my program, but something is wrong in my code , and I didn't arrive to
> know it
> this is my code
>
>
> import org.snmp4j.*;
> import org.snmp4j.event.*;
> import org.snmp4j.smi.*;
> import org.snmp4j.transport.*;
> import java.io.*;
> import org.snmp4j.CommunityTarget;
> import org.snmp4j.util.*;
>
> public class Test
> {
> public static void main(String[] args)throws IOException {
> // TODO code application logic here
> CommunityTarget target = new CommunityTarget();
> Address targetaddress = new UdpAddress("172.17.200.19/161");
> target.setAddress(targetaddress);
> target.setCommunity(new OctetString("public"));
> target.setTimeout (1000);
> target.setVersion(0);
> target.setRetries(1);
>
> PDU pdu = new PDU();
> pdu.setType(PDU.V1TRAP);
>
>
>
> pdu.add(new VariableBinding(new OID(".1.3.6.1.2.1.25.3.3.1.2")));
> TransportMapping transport = new DefaultUdpTransportMapping();
> transport.listen();
> try
> {
>
> Snmp snmp = new Snmp(transport);
>
> ResponseEvent respEv = snmp.send(pdu, target);
>
> PDU response = respEv.getResponse();
>
>
>
> }
>
> catch (Exception e)
> {
> System.out.println("Errror in snmp");
> }
> }
> }
> _______________________________________________
> 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