SNMP服务器连接

VJS*_*VJS 1 snmp

我正在向SNMP服务器发送SNMP陷阱.但是如果没有建立与服务器的连接,我必须打印日志.

UdpAddress targetAddress = new UdpAddress("127.0.0.1/1985");

CommunityTarget target = new CommunityTarget();

target.setCommunity(new OctetString("public"));

target.setAddress(targetAddress);

target.setRetries(2);

target.setTimeout(1000); 

target.setVersion(SnmpConstants.version1);

Snmp snmp = new Snmp(new DefaultUdpTransportMapping());

snmp.listen();

// prepare the PDU for sending

PDU command = new PDU();

command.setType(PDU.GET);

command.add(new VariableBinding(new

OID("1.3.6.1.4.1.1331.11.5.1.0")));

// now send the PDU

**//  I HAVE TO CHECK WETHER CONNECTION IS ESTABLISHED OR NOT WITH SNMP SERVER. AS OF
NOW EVEN IF I DO NOT START SNMP SERVER THAN I AM NOT GETTING ANY EXCEPTION and IF I START 
SNMP SERVER THEN MESSAGE HAS BEEN SENT TO SNMP SERVER.....MAY BE IN SEND METHOD..ITS
CONNECTS WITH SNMP SERVER....BUT I TRIED TO FIND OUT BUT COULDNT ABLE TO DO IT.....**

ResponseEvent responseEvent = snmp.send(pdu, target);
Run Code Online (Sandbox Code Playgroud)

Lex*_* Li 5

UDP是无连接的,因此在这种情况下您无法知道是否收到了数据包.