Or Continue to Thread: [Q] Snmp Get request error
Find Your Device:
22nd March 2014, 03:46 PM   |  #1  
OP Junior Member
Thanks Meter: 0
 
1 posts
Join Date:Joined: Mar 2014
Hi
I'm build an android application using WebNMS library that apply snmp get operation on router but the result is null and this is the error message
"Error Sending PDU. IO error sending PDU. Send Error: null"
this is my code :
Code:
package com.example.snmptst;

import com.adventnet.snmp.beans.SnmpTarget;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.Toast;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
			SnmpTarget target;
			String targetHost;
			int targetPort;
			String community;			
			int timeout;
			int retries;
		    String returnString = null;	    	
		    targetHost = "192.168.1.1";		
			targetPort = 161;	
			community = "public";	
			timeout = 5000;			
			retries = 2;			
			
			
			// Use an SNMP target bean to perform SNMP operations
			target = new SnmpTarget();
			target.setTargetHost(targetHost);	// set the agent hostname
			if(community != null) {	// set the community if specified
				target.setCommunity(community);
			}
			target.setTargetPort(targetPort);	// set the port, default is 161
			
			// set the timeout/retries parameters, default are 5 and 0
			target.setTimeout(timeout);
			target.setRetries(retries);
			// Create oidList array from the obtained arrayList
			String []oidList = new String[1];
			oidList[0]=".1.3.6.1.2.1.1.5.0";
			// Set the OID List on the SnmpTarget instance
			target.setObjectIDList(oidList);
			
			String[] result = target.snmpGetList();	// do a get request
			
			// Return the result/error from the response.
			if(result != null) {
				String successString = "Response received.  Values:\n";		//No I18N
				for(int k=0; k<result.length; k++) {
					successString = successString + target.getObjectID(k) + " : " + result[k] + "\n";	//No I18N
				}
				returnString = successString;
			} else {
				String errorString = "Request Failed or Timed-out. \n";		//No I18N
				errorString = errorString + target.getErrorString();
				returnString = errorString;
			}
			Toast.makeText(getApplicationContext(), returnString, Toast.LENGTH_LONG).show();
		        
		    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
    
}
Any one can help me?
Thanks.