File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Sockets and Internet Protocols and the fly likes java.net.SocketTimeoutException: Receive timed out Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Reply Bookmark "java.net.SocketTimeoutException: Receive timed out" Watch "java.net.SocketTimeoutException: Receive timed out" New topic
Author

java.net.SocketTimeoutException: Receive timed out

nikunj shingala
Ranch Hand

Joined: Jul 20, 2009
Posts: 30
Hi,

I am new in this filed and try to run one example of SNMP but when i run that time below Exception are generated so please please help me...

Retrieving value corresponding to OID 1.3.6.1.2.1.1.1.0

Exception during SNMP operation: java.net.SocketTimeoutException: Receive timed out

Hear is my code .........So please check them and solve my exception .........


public class SNMPSampleSetGet
{
public static void main(String args[])
{

try
{

// create a communications interface to a remote SNMP-capable device;
// need to provide the remote host's InetAddress and the community
// name for the device; in addition, need to supply the version number
// for the SNMP messages to be sent (the value 0 corresponding to SNMP
// version 1)
InetAddress hostAddress = InetAddress.getByName("172.30.12.107");
String community = "public";
int version = 0; // SNMPv1

SNMPv1CommunicationInterface comInterface = new SNMPv1CommunicationInterface(version, hostAddress, community);



// now send an SNMP GET request to retrieve the value of the SNMP variable
// corresponding to OID 1.3.6.1.2.1.1.1.0; this is the OID corresponding to
// the device identifying string, and the type is thus SNMPOctetString
String itemID = "1.3.6.1.2.1.1.1.0";

System.out.println("Retrieving value corresponding to OID " + itemID);

// the getMIBEntry method of the communications interface returns an SNMPVarBindList
// object; this is essentially a Vector of SNMP (OID,value) pairs. In this case, the
// returned Vector has just one pair inside it.
SNMPVarBindList newVars = comInterface.getMIBEntry(itemID);

// extract the (OID,value) pair from the SNMPVarBindList; the pair is just a two-element
// SNMPSequence
SNMPSequence pair = (SNMPSequence)(newVars.getSNMPObjectAt(0));

// extract the object identifier from the pair; it's the first element in the sequence
SNMPObjectIdentifier snmpOID = (SNMPObjectIdentifier)pair.getSNMPObjectAt(0);

// extract the corresponding value from the pair; it's the second element in the sequence
SNMPObject snmpValue = pair.getSNMPObjectAt(1);

// print out the String representation of the retrieved value
System.out.println("Retrieved value: type " + snmpValue.getClass().getName() + ", value " + snmpValue.toString());

// the retrieved value can be obtained from the SNMPObject using the getValue method;
// the return type of the method is the generic base class Object, and must be cast to
// the appropriate actual Java type; in this case, for an SNMPOctetString, the underlying
// Java type is a byte array[]
byte[] javaByteArrayValue = (byte[])snmpValue.getValue();



// now send an SNMP GET request to retrieve the value of the SNMP variable
// corresponding to OID 1.3.6.1.2.1.1.3.0; this is the OID corresponding to
// the uptime of the device, and the return type is thus SNMPTimeTicks
itemID = "1.3.6.1.2.1.1.3.0";

System.out.println("Retrieving value corresponding to OID " + itemID);

// the getMIBEntry method of the communications interface returns an SNMPVarBindList
// object; this is essentially a Vector of SNMP (OID,value) pairs. In this case, the
// returned Vector has just one pair inside it.
newVars = comInterface.getMIBEntry(itemID);

// extract the (OID,value) pair from the SNMPVarBindList; the pair is just a two-element
// SNMPSequence
pair = (SNMPSequence)(newVars.getSNMPObjectAt(0));

// extract the object identifier from the pair; it's the first element in the sequence
snmpOID = (SNMPObjectIdentifier)pair.getSNMPObjectAt(0);

// extract the corresponding value from the pair; it's the second element in the sequence
snmpValue = pair.getSNMPObjectAt(1);

// print out the String representation of the retrieved value
System.out.println("Retrieved value: type " + snmpValue.getClass().getName() + ", value " + snmpValue.toString());

// the retrieved value can be obtained from the SNMPObject using the getValue method;
// the return type of the method is the generic base class Object, and must be cast to
// the appropriate actual Java type; in this case, for SNMPTimeTicks, which is a subclass
// of SNMPInteger, the actual type is BigInteger (which permits arbitrarily large values to
// be represented).
BigInteger javaIntegerValue = (BigInteger)snmpValue.getValue();



// now send an SNMP SET request to set the value of the SNMP variable
// corresponding to OID 1.3.6.1.2.1.1.1.0; this is the OID corresponding to
// the device identifying string, and the type is thus SNMPOctetString;
// to set a new value, a string is supplied
itemID = "1.3.6.1.2.1.1.1.0";

SNMPOctetString newValue = new SNMPOctetString("New device name");

System.out.println("Setting value corresponding to OID " + itemID);
System.out.println("New value: " + newValue.toString());

// the setMIBEntry method of the communications interface returns the SNMPVarBindList
// corresponding to the supplied OID and value
// This call will probably cause an SNMPSetException to be thrown, since the
// community name "public" is probably not the read/write password of the device
newVars = comInterface.setMIBEntry(itemID, newValue);



}
catch(Exception e)
{
System.out.println("Exception during SNMP operation: " + e + "\n");
}

}

}

Please solve my exception as possible as early ................
 
 
subject: java.net.SocketTimeoutException: Receive timed out
 
Threads others viewed
need help with java
Simple J2SE 5.0 Tiger Notes
can the cause of memory leak be detected here?
Objects in JSP
Filling Array
IntelliJ Java IDE