[SNMP4J] Not able to send SNMP Trap Using DefaultTcpTransportMapping

vikas br vikas.br2 at gmail.com
Wed Mar 30 16:25:16 CEST 2016


I have to some traps on TCP 162  of Trap Receiver. But I am not able to
send snmp trap on that server using snmp4j jar.

I can send traps using DefaultUdpTransportMapping but not with
DefaultTcpTransportMapping.


Our Trap Receiver is listen on both tcp:1622 and udp:1622 port.

Please let me know how can I achieve that.

Code is below
-------------------


TransportMapping transport = null;
TransportIpAddress address=null;
try {
address=new TcpAddress("<ip-address>"+"/"+1622);
transport=new DefaultTcpTransportMapping();
// address=new UdpAddress("ip-address"+"/"+1622);
// transport=new DefaultUdpTransportMapping();
transport.listen();
Snmp snmp = new Snmp(transport);
CommunityTarget target = new CommunityTarget();
target.setCommunity(new OctetString("secure"));
target.setVersion(SnmpConstants.version2c);
target.setAddress(address);
target.setRetries(1);
target.setTimeout(2000);
VariableBinding[] appSpecVbs = getTestVarBinds();
PDU pdu = new PDU();
pdu.addAll(appSpecVbs);
pdu.setType(PDU.TRAP);
snmp.send(pdu, target);
transport.close();
snmp.close();

} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}



More information about the SNMP4J mailing list