[SNMP4J] problem regarding example code

Frank Fock fock at agentpp.com
Wed Nov 29 21:15:26 CET 2006


Hello,

The code below should produce a NullPointerException
(address is not initialized). So I wonder why it does
not print out a stack trace.

Anyway, you should call snmp.listen() and then wait
in the main thread for ever (or your process is shut
down).

Best regards,
Frank

bhushan wrote:
> hello friends,
> I am newbie to snmp4j. I have started using snmp4j, at initial stages
> i am just trying example code, so i am facing problem in running those
> i have written sample code which will listen for snmp3 request & on
> receiving
> request it just dump request on console, code is as follows
> 
> ------------------------------------------------------------------------------------------------------------------ 
> 
> import java.io.IOException;
> import java.net.InetAddress;
> import org.snmp4j.CommandResponder;
> import org.snmp4j.CommandResponderEvent;
> import org.snmp4j.PDU;
> import org.snmp4j.Snmp;
> import org.snmp4j.TransportMapping;
> import org.snmp4j.mp.MPv3;
> import org.snmp4j.mp.MessageProcessingModel;
> import org.snmp4j.mp.SnmpConstants;
> import org.snmp4j.security.SecurityModels;
> import org.snmp4j.security.SecurityProtocols;
> import org.snmp4j.security.USM;
> import org.snmp4j.smi.OctetString;
> import org.snmp4j.smi.UdpAddress;
> import org.snmp4j.transport.DefaultUdpTransportMapping;
> import org.snmp4j.transport.TransportMappings;
> 
> import sun.net.InetAddressCachePolicy;
> import java.net.InetAddress;
> import com.sun.jndi.cosnaming.IiopUrl.Address;
> 
> 
> public class main_listen{
> 
>    public static void main(String arg[]) throws IOException  {
>        // TODO Auto-generated method stub
>        java.net.InetAddress address = null;
>        String data = "0.0.0.0";
>        InetAddress.getByName(data);
>        int port=161;
>        TransportMapping transport =
>            new DefaultUdpTransportMapping(new UdpAddress(address, port));
>        Snmp snmp = new Snmp(transport);
>        int version = 0;
>        if (version == SnmpConstants.version3) {
>            byte[] localEngineID =
>                MPv3.createLocalEngineID();
>            USM usm = new USM(SecurityProtocols.getInstance(),
>                              new OctetString(localEngineID), 0);
>            SecurityModels.getInstance().addSecurityModel(usm);
>            snmp.setLocalEngine(localEngineID, 0, 0);
> 
>            CommandResponder trapPrinter = new CommandResponder() {
>                public synchronized void processPdu(CommandResponderEvent e)
> {
>                  PDU command = e.getPDU();
>                  if (command != null) {
>                    System.out.println(command.toString());
>                  }
>                }
>              };
>            snmp.addCommandResponder(trapPrinter);
>            transport.listen();
>            // Add the configured user to the USM
> 
>    };
> 
> }
> }
> 
> ------------------------------------------------------------------------------------------------------ 
> 
> 
> But  problem with my code is when i run this code it just run for second.
> & exits, also it not showing any error/ exception on console.  i am unable
> to understand what is happening.as far as i understood from this code,
> is this code should wait for request & on receiving request it should dump
> data
> on console. but what is happening
> i am unable to understand,
> so Is my interpretation  correct or not ?
> Is any thing wrong done by me in code ?
> Please help me.
> Thanks in advance
> Regards
> Bhushan E. Sonawane
> _______________________________________________
> 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