title: SNMP Server Connection
body: <p>I am sending a SNMP trap to the SNMP server. But I have to print the log if the connection to the server is not established.</p>
  
  <pre><code>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);
  </code></pre>