Ivan, You are using the target address also as your local address. This cannot work for addresses other than local addresses.
Regards, Frank On 19.01.2010 14:24, Ivan Mladenović wrote: > I'm trying to send snmp V2 trap from my java code. Everything works fine > when both (manager and agent) are on localhost, > but if I try to send a trap to manager that is on another machine, I don't > receive any traps. If I use some other program > for generating traps (for example "SNMP trap stormer" from AdventNet > simulation toolkit 7) I don't have this issue. > > Here is my code: > void confgure() throws UnknownHostException, IOException { > // Create the Manager address > UdpAddress managerUdpAddress = new > UdpAddress(InetAddress.getByName(managerHost), managerPort); > // works fine when manager host="127.0.0.1" > // Create the Agent address > UdpAddress agentUdpAddress = new > UdpAddress(InetAddress.getByName(agentHost), agentPort); > > // Create the Community Target using the manager address > ctarget = new CommunityTarget(managerUdpAddress, new > OctetString(community)); > ctarget.setCommunity(new OctetString(community)); > ctarget.setRetries(retries); > ctarget.setTimeout(timeout); > > // Create the Transport Mapping using the agent address > ctransport = new DefaultUdpTransportMapping(agentUdpAddress); > // Create the session object > snmp = new Snmp(ctransport); > } > > .... > sending trap: > > public void sendV2Trap(String trapOid, String message) throws Exception { > > long sysUpTime = (System.currentTimeMillis() / 10) - startTime; > sysUpTime = sysUpTime % MAX_SYSUPTIME; > // Set SNMP version as V2 > ctarget.setVersion(SnmpConstants.version2c); > // Create trap with time ticks, the trap OID and the message > PDU trapPdu = new PDU(); > > trapPdu.add(new VariableBinding(new OID(SYS_UP_TIME), new > TimeTicks(sysUpTime))); > trapPdu.add(new VariableBinding(new OID(SNMP_TRAP_OID), new > OID(trapOid))); > trapPdu.add(new VariableBinding(new OID(trapOid), new > OctetString(message.getBytes()))); > > // Send trap > snmp.notify(trapPdu, ctarget); > } > > > P.S. To view received traps, I use Trap Receiver ( > http://www.trapreceiver.com/) > _______________________________________________ > SNMP4J mailing list > SNMP4J@agentpp.org > http://lists.agentpp.org/mailman/listinfo/snmp4j -- AGENT++ http://www.agentpp.com http://www.snmp4j.com http://www.mibexplorer.com http://www.mibdesigner.com _______________________________________________ SNMP4J mailing list SNMP4J@agentpp.org http://lists.agentpp.org/mailman/listinfo/snmp4j