[SNMP4J] BindException error

Frank Fock fock at agentpp.com
Sat Dec 13 10:28:48 CET 2008


Hi Diago,

You are trying to send a packet to the port you are trying to listen on.
As long as there is another process bound to that port (the snmp service
of your OS), this will fail.

You will have to use a different listen address (e.g. "udp:0.0.0.0/0")
to make this working.

Regards,
Frank

Diogo Vasconcellos wrote:
> 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
> _______________________________________________
> 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