Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/312.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用SNMP4j和Java的多个SNMP代理_Java_Snmp4j - Fatal编程技术网

使用SNMP4j和Java的多个SNMP代理

使用SNMP4j和Java的多个SNMP代理,java,snmp4j,Java,Snmp4j,我正在尝试创建一个snmp代理模拟器应用程序,它将创建具有唯一ip地址和端口的多个虚拟代理。我正在尝试使用snmp4jagent。但是我有一些例外,你能帮我吗 我将BaseAgent类扩展到自己的类,然后创建该类的多个实例。但我不能一次启动多个代理,即,如果一个代理的状态为“正在运行”,我无法启动另一个代理而不停止正在运行的代理(代码太重,因此我在此不指定任何代码)。启动代理的代码为 public void start() throws IOException { init();

我正在尝试创建一个snmp代理模拟器应用程序,它将创建具有唯一ip地址和端口的多个虚拟代理。我正在尝试使用snmp4jagent。但是我有一些例外,你能帮我吗

我将BaseAgent类扩展到自己的类,然后创建该类的多个实例。但我不能一次启动多个代理,即,如果一个代理的状态为“正在运行”,我无法启动另一个代理而不停止正在运行的代理(代码太重,因此我在此不指定任何代码)。启动代理的代码为

public void start() throws IOException
{
    init();
    addShutdownHook();
    getServer().addContext(new OctetString("public"));
    finishInit();
    run();
    sendColdStartNotification(); 
}
然后我注册托管对象

代码参考:

提前谢谢

Pramod实际上是有效的(经过测试)。可能您没有为不同的实例分配不同的IP地址。将此添加到您的类:

/**
 * The ip address of this agent.
 */
private String ipAddress;

/**
 * Initializes the transport mappings (ports) to be used by the agent.
 * 
 * @throws IOException
 */ 
protected void initTransportMappings() throws IOException {
    transportMappings = new TransportMapping[1];
    transportMappings[0] = new DefaultUdpTransportMapping(new UdpAddress(ipAddress + "/161"));
}
您可能需要将使用过的ip地址添加到NIC中。Linux的示例:

ip addr add 10.0.0.2/24 dev eth0

如果仍然无法启动第二个代理,请提供异常消息和堆栈跟踪。

提供更多详细信息和代码片段。请不要再问同样的问题。您始终可以使用此选项添加详细信息或修复格式。谢谢