[SNMP4J] Listen and send commands from the same port

Frank Fock fock at agentpp.com
Mon Mar 10 08:26:03 CET 2014


Hi,

Your code below has a few issues. First of all, you should not
use the MultiThreadedMessageDispatcher before you got the
default up and running. In most cases, you do not need it
anyway.

Second, call snmp.listen() if you have setup SNMP and not when
you add some notification listener addresses.

Some code seems to be missing, so that further analyisis is not
possible.

Best regards,
Frank

Am 05.03.2014 13:29, schrieb Nikodem DobrzaƄski:
> Hi everyone
>
> I tried create a snmp object that listen incoming messages/responses on 162
> UDP port number and is able to send getnext command  from port 162 UDP only
> to 161 (others ports are not available). Object listen traps without
> problems but there's no command response. Message model processing is
> SNMPv1.
> I usually get error org.snmp4j.transport.UnsupportedAddressClassException:
> Unsupported address class (transport mapping): org.snmp4j.smi.UdpAddress
>
> Pieces of used code below
>
> private TransportMapping transport = null;
> private MessageDispatcher mtDispatcher = null;
>
> // for listen
> public synchronized void listen(TransportIpAddress address) throws
> IOException
> {
> InetAddress managerIpAddress = InetAddress.getLocalHost();
> UdpAddress managerUdpAddress = new UdpAddress(managerIpAddress, 162);
> this.transport = new DefaultUdpTransportMapping(managerUdpAddress);
> ThreadPool threadPool = ThreadPool.create("DispatcherPool", 10);
> this.mtDispatcher = new MultiThreadedMessageDispatcher(threadPool, new
> MessageDispatcherImpl());
> this.mtDispatcher.addMessageProcessingModel(new MPv1());
> SecurityProtocols.getInstance().addDefaultProtocols();
> snmp = new Snmp(mtDispatcher, transport);
>
> CommandResponder trapPrinter = new CommandResponder()
> {
> @Override
>          public synchronized void processPdu(CommandResponderEvent
> cmdRespEvent) {
>                  PDU pdu = cmdRespEvent.getPDU();
> ...
> }
> };
>
>
> if(snmp.addNotificationListener(listenResponseAddress, trapPrinter))
>          {
>              snmp.listen();
> ...
> }
>
> // for send
> public void SendGetNext(){
> Address add = GenericAddress.parse("udp" + ":" + "196.31.82.19" + "/" +
> 161);
> CommunityTarget comtarget = new CommunityTarget();
>          comtarget.setCommunity(new OctetString("ABC"));
>          comtarget.setVersion(SnmpConstants.version1);
>          comtarget.setAddress(add);
>          comtarget.setRetries(2);
>          comtarget.setTimeout(1000);
>
> OID rootOid = new OID("1.3.6.1.4.1.191"); // example
>          PDU pdu = new PDU();
>          pdu.add(new VariableBinding(rootOid));
>          pdu.setType(PDU.GETNEXT);
>
> try{
> this.snmp.send(pdu, comtarget);
> }
> catch(IOException ex){
>              System.out.println("Error" + ex.toString());
> }
> _______________________________________________
> SNMP4J mailing list
> SNMP4J at agentpp.org
> https://s16675406.onlinehome-server.info/mailman/listinfo/snmp4j

-- 
---
AGENT++
Maximilian-Kolbe-Str. 10
73257 Koengen, Germany
https://agentpp.com
Phone: +49 7024 8688230
Fax:   +49 7024 8688231




More information about the SNMP4J mailing list