[SNMP4J] BindException error

Diogo Vasconcellos diogovasconcellos at gmail.com
Fri Dec 12 22:35:18 CET 2008


Hi,

I'm using SNMP4J v 1.9.3c, and every time I run my code I'm getting a
java.net.BindException: Address already in use: Cannot bind. The weird thing
is that yesterday it ran OK when querying 127.0.0.1/161. I'm using Windows
XP, and its own SNMP service.


How could I solve that, or find the answer? What am I doing wrong?


Here's my code (the SNMP part)


    public static String testaOID (String endereco, String oid, String
community)
    {
        String resultado = null;

        // PDU.
        PDU pdu = new PDU();
        pdu.add(new VariableBinding(new OID(oid))); // sysDescr
        pdu.setType(PDU.GETNEXT);

        // Target
        CommunityTarget target = new CommunityTarget();
        target.setCommunity(new OctetString(community));
        target.setAddress(new UdpAddress(endereco));
        target.setVersion(SnmpConstants.version2c);

        System.out.println(target.toString());


        ResponseEvent response = null;
        Snmp snmp = null;

        // connection
        try
        {
            // SNMP instance
            snmp = new Snmp ( new DefaultUdpTransportMapping (new
UdpAddress(endereco) ) );
            System.out.println(snmp.toString());
            snmp.listen();
        }
        catch (Exception e)
        {
            System.out.println("1 - "+e.toString());
        }



        try
        {
            response = snmp.send(pdu, target);
        }
        catch ( Exception e )
        {
            System.out.println("2 - "+e.toString());
        }



        try
        {
            // timeout...
            if (response.getResponse() == null)
            {
                System.out.println("TIMEOUT");
            }
            else {
                // returns response
                System.out.println("Received response from: "+
response.getPeerAddress());
                // dump response PDU
                resultado = response.getResponse().toString();
            }

        } catch ( Exception e)
        {
            System.out.println("3 - "+e.toString());
        }

        // returns response
        return resultado;
    }



Sincere thanks,
Diogo Vasconcellos



More information about the SNMP4J mailing list