在本机中使用SNMPJS

时间:2017-10-24 18:19:37

标签: javascript react-native

我想使用SNMP连接到打印机,我遇到了这个库 - https://github.com/pdlove/react-native-snmp-native。但是,当我尝试在reactnative平台中使用相同的时候,我得到了错误。

import snmp from 'net-snmp';
const session = snmp.createSession('10.20.27.221', 'public', 161);
const oids = ['1.3.6.1.2.1.1.5.0', '1.3.6.1.2.1.1.6.0'];

session.get(oids, (error, varbinds) => {
if (error) {
    console.error(error);
} else {
        console.log(varbinds[0].value);
  }
});
session.trap(snmp.TrapType.LinkDown, (error) => {
if (error) {
    console.error(error);
}
});

当我尝试执行上面的代码时,我在android模拟器上得到以下错误

The development server returned response error code: 500
URL: http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false

Body:
{"from":"/Users/Documents/projects/auth/node_modules/net-snmp/index.js","to":"dgram","message":"Unable to resolve module dgram from /Users/Documents/projects/auth/node_modules/net-snmp/index.js: Module does not exist in the module map\n\nThis might be related to https://github.com/facebook/react-native/issues/4968\nTo resolve try the following:\n 1. Clear watchman watches: watchman watch-del-all.\n 2. Delete the node_modules folder: rm -rf node_modules && npm install.\n 3. Reset packager cache: rm -fr $TMPDIR/react-* or npm start -- --reset-cache.","name":"UnableToResolveError","type":"UnableToResolveError","errors":[{}]}
processBundleResult
BundleDownloader.java:225
access$100
BundleDownloader.java:40
onResponse
BundleDownloader.java:192
execute
RealCall.java:135
run
NamedRunnable.java:32
runWorker
ThreadPoolExecutor.java:1162
run
ThreadPoolExecutor.java:636
run
Thread.java:764

有没有人使用过反应原生的SNMP协议?最好的方法是什么?

0 个答案:

没有答案