I think it has to do with application thread shutting down before the response is received, because a response is received when sync request is made (snmp.get) Also, later, I was able to get the response some times, with the same code below. For broadcast address however, I never receive a response. I will try increasing timeout and see there is any luck. Thank you for your help..
Thanks, Shraddha. -----Original Message----- From: Frank Fock [mailto:[email protected]] Sent: Monday, June 30, 2014 4:16 PM To: Shraddha Herlekar; [email protected] Subject: Re: [SNMP4J] SNMP Agent discovery Hi Shraddha, The code seems to be OK for itself. However, maybe the main thread shuts down the application before the response has been received? Or the agent is the problem source. Also check the network... Best regards, Frank Am 01.07.2014 00:05, schrieb Shraddha Herlekar: > Hi Frank, > > Thank you for your reply. Following your suggestion I implemented the method > shown below. It doesn't test broadcast yet. It is currently calling GET > method on an agent. > After sending async request (using snmp.send(pdu, target, null, listener);), > I think 'onResponse' method is never invoked. > I am not sure what am I missing. Could you please help? > Thanks!! > > public static void testBroadcast() throws IOException { > Address targetAddress = > GenericAddress.parse("udp:172.17.77.112/161"); > // Broadcast address: > // Address targetAddress = new UdpAddress("172.17.77.255/161"); > TransportMapping transport; > > try { > transport = new DefaultUdpTransportMapping(); > transport.listen(); > snmp = new Snmp(transport); > } catch (IOException e1) { > // TODO Auto-generated catch block > e1.printStackTrace(); > } > > // setting up target > CommunityTarget target = new CommunityTarget(); > target.setCommunity(new OctetString("public")); > target.setAddress(targetAddress); > target.setRetries(2); > target.setTimeout(5000); > target.setVersion(SnmpConstants.version1); > > // creating PDU > PDU pdu = new PDU(); > pdu.add(new VariableBinding(new OID(new int[] { 1, 3, 6, 1, 2, > 1, 1, 1, > 0 }))); > pdu.add(new VariableBinding(new OID(new int[] { 1, 3, 6, 1, 2, > 1, 1, 2, > 0 }))); > pdu.setType(PDU.GET); > System.out.println("Sending async request"); > > // send Async request > ResponseListener listener = new ResponseListener() { > public void onResponse(ResponseEvent resEvent) { > // Always cancel async request when response > has been received > // otherwise a memory leak is created! Not > canceling a request > // immediately can be useful when sending a > request to a > // broadcast > // address. > > ((Snmp) > resEvent.getSource()).cancel(resEvent.getRequest(), > this); > System.out.println("Received response PDU is: " > + resEvent.getResponse()); > } > }; > > snmp.send(pdu, target, null, listener); > > } > > Thanks, > Shraddha. > > -----Original Message----- > From: SNMP4J [mailto:[email protected]] On Behalf Of Frank > Fock > Sent: Friday, June 27, 2014 11:53 AM > To: [email protected] > Subject: Re: [SNMP4J] SNMP Agent discovery > > Hi Shraddha, > > Yes, of course. MIB Explorer is based on SNMP4J and its network discovery > engine is based on SNMP4J. > Use the asynchronous request interface in conjunction with the broadcast > address and use the cancel method by timeout (and not for each response as > usual). > > Best regards, > Frank > > Am 27.06.2014 19:21, schrieb Shraddha Herlekar: >> Hi, >> >> Is it possible to discover SNMP agents in a network using SNMP4J? >> I am looking for a functionality that any MIB browser provides for Network >> Discovery, which results into list of SNMP agents, IP Address, sysDescr >> ..etc, given a Subnet IP. >> >> TIA, >> Shraddha. >> >> _______________________________________________ >> SNMP4J mailing list >> [email protected] >> https://oosnmp.net/mailman/listinfo/snmp4j > -- > --- > AGENT++ > Maximilian-Kolbe-Str. 10 > 73257 Koengen, Germany > https://agentpp.com > Phone: +49 7024 8688230 > Fax: +49 7024 8688231 > > _______________________________________________ > SNMP4J mailing list > [email protected] > https://oosnmp.net/mailman/listinfo/snmp4j -- --- AGENT++ Maximilian-Kolbe-Str. 10 73257 Koengen, Germany https://agentpp.com Phone: +49 7024 8688230 Fax: +49 7024 8688231 _______________________________________________ SNMP4J mailing list [email protected] https://oosnmp.net/mailman/listinfo/snmp4j
