abod abod
- Forum posts: 1
Mar 22, 2014, 1:48:57 PM via Website
Mar 22, 2014 1:48:57 PM via Website
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 :
Thanks.
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 :
1package com.example.snmptst;
2
3import com.adventnet.snmp.beans.SnmpTarget;
4import android.os.Bundle;
5import android.app.Activity;
6import android.view.Menu;
7import android.widget.Toast;
8
9public class MainActivity extends Activity {
10
11 @Override
12 protected void onCreate(Bundle savedInstanceState) {
13 super.onCreate(savedInstanceState);
14 setContentView(R.layout.activity_main);
15
16 SnmpTarget target;
17 String targetHost;
18 int targetPort;
19 String community;
20 int timeout;
21 int retries;
22 String returnString = null;
23 targetHost = "192.168.1.104";
24 targetPort = 161;
25 community = "public";
26 timeout = 5000;
27 retries = 2; //No I18N
28
29
30 // Use an SNMP target bean to perform SNMP operations
31 target = new SnmpTarget();
32 target.setTargetHost(targetHost); // set the agent hostname
33 if(community != null) { // set the community if specified
34 target.setCommunity(community);
35 }
36 target.setTargetPort(targetPort); // set the port, default is 161
37
38 // set the timeout/retries parameters, default are 5 and 0
39 target.setTimeout(timeout);
40 target.setRetries(retries);
41 // Create oidList array from the obtained arrayList
42 String []oidList = new String[1];
43 oidList[0]=".1.3.6.1.2.1.1.5.0";
44 // Set the OID List on the SnmpTarget instance
45 target.setObjectIDList(oidList);
46
47 String[] result = target.snmpGetList(); // do a get request
48
49 // Return the result/error from the response.
50 if(result != null) {
51 String successString = "Response received. Values:\n"; //No I18N
52 for(int k=0; k<result.length; k++) {
53 successString = successString + target.getObjectID(k) + " : " + result[k] + "\n"; //No I18N
54 }
55 returnString = successString;
56 } else {
57 String errorString = "Request Failed or Timed-out. \n"; //No I18N
58 errorString = errorString + target.getErrorString();
59 returnString = errorString;
60 }
61 Toast.makeText(getApplicationContext(), returnString, Toast.LENGTH_LONG).show();
62
63 }
64
65
66 @Override
67 public boolean onCreateOptionsMenu(Menu menu) {
68 // Inflate the menu; this adds items to the action bar if it is present.
69 getMenuInflater().inflate(R.menu.main, menu);
70 return true;
71 }
72
73}
Any one can help me?2
3import com.adventnet.snmp.beans.SnmpTarget;
4import android.os.Bundle;
5import android.app.Activity;
6import android.view.Menu;
7import android.widget.Toast;
8
9public class MainActivity extends Activity {
10
11 @Override
12 protected void onCreate(Bundle savedInstanceState) {
13 super.onCreate(savedInstanceState);
14 setContentView(R.layout.activity_main);
15
16 SnmpTarget target;
17 String targetHost;
18 int targetPort;
19 String community;
20 int timeout;
21 int retries;
22 String returnString = null;
23 targetHost = "192.168.1.104";
24 targetPort = 161;
25 community = "public";
26 timeout = 5000;
27 retries = 2; //No I18N
28
29
30 // Use an SNMP target bean to perform SNMP operations
31 target = new SnmpTarget();
32 target.setTargetHost(targetHost); // set the agent hostname
33 if(community != null) { // set the community if specified
34 target.setCommunity(community);
35 }
36 target.setTargetPort(targetPort); // set the port, default is 161
37
38 // set the timeout/retries parameters, default are 5 and 0
39 target.setTimeout(timeout);
40 target.setRetries(retries);
41 // Create oidList array from the obtained arrayList
42 String []oidList = new String[1];
43 oidList[0]=".1.3.6.1.2.1.1.5.0";
44 // Set the OID List on the SnmpTarget instance
45 target.setObjectIDList(oidList);
46
47 String[] result = target.snmpGetList(); // do a get request
48
49 // Return the result/error from the response.
50 if(result != null) {
51 String successString = "Response received. Values:\n"; //No I18N
52 for(int k=0; k<result.length; k++) {
53 successString = successString + target.getObjectID(k) + " : " + result[k] + "\n"; //No I18N
54 }
55 returnString = successString;
56 } else {
57 String errorString = "Request Failed or Timed-out. \n"; //No I18N
58 errorString = errorString + target.getErrorString();
59 returnString = errorString;
60 }
61 Toast.makeText(getApplicationContext(), returnString, Toast.LENGTH_LONG).show();
62
63 }
64
65
66 @Override
67 public boolean onCreateOptionsMenu(Menu menu) {
68 // Inflate the menu; this adds items to the action bar if it is present.
69 getMenuInflater().inflate(R.menu.main, menu);
70 return true;
71 }
72
73}
Thanks.
— modified on Mar 22, 2014, 1:50:26 PM
Recommended editorial content
With your consent, external content is loaded here.
By clicking on the button above, you agree that external content may be displayed to you. Personal data may be transmitted to third-party providers in the process. You can find more information about this in our Privacy Policy.