[SNMP4J] synchronous get v2

Thomas, Craig thomasc at tycoelectronics.com
Fri Dec 23 18:47:41 CET 2005


I am having some basic trouble doing a synchronous get of version 2c.

I have an Agent Simulator set up at port 8002 and have written a test
program using AdventNet api to validate that it is working.

When I do the send my ResponseEvent contains a response of null. I am
guessing that I am missing something very simple. Does anyone have any
ideas (code at end)? Or better yet some examples of synchronous v2c that
could help me out.

Thanks
Craig


public class SnmpTest
{
//    static final OID SNMP_MIB2_SYSCONTACT_OID = new
OID(".1.3.6.1.2.1.1.4");
//    static final OID SNMP_MIB2_SYSCONTACT_OID = new
OID(".1.3.6.1.2.1.1.4.0");
    static final OID SNMP_MIB2_SYSCONTACT_OID = new
OID("1.3.6.1.2.1.1.4");
//    static final OID SNMP_MIB2_SYSCONTACT_OID = new
OID("1.3.6.1.2.1.1.4.0");

    public static void main(String[] args)
        throws IOException
    {
        InetAddress targetAddress = InetAddress.getByName("localhost");
        Snmp snmp = new Snmp(new DefaultUdpTransportMapping());

        PDUFactory factory = new DefaultPDUFactory();
        CommunityTarget target = new CommunityTarget();

        target.setAddress(new UdpAddress(targetAddress, 8002));
        target.setCommunity(new OctetString("public"));
        target.setTimeout(1000);
        target.setVersion(SnmpConstants.version2c);
        target.setRetries(1);

        PDU pdu = factory.createPDU(target);
        pdu.setType(PDU.GET);
        pdu.add(new VariableBinding(SNMP_MIB2_SYSCONTACT_OID));

        ResponseEvent response = snmp.send(pdu, target);
        if (response == null || response.getResponse() == null)
        {
            System.out.println("Time-out getting data ");
        }
    }

}





More information about the SNMP4J mailing list