cannot connect to remote jmx agent
hello,
i have a jmx agent code:
...
MBeanServer mbs= ManagementFactory.getPlatformMBeanServer();
String domain = mbs.getDefaultDomain();
ObjectName name = new ObjectName(domain+":type=Test");
TestMBean mbean= new Test();
mbs.registerMBean(mbean, name);
JMXServiceURL url= new JMXServiceURL("service:jmx:rmi:///jndi/rmi://"+rmi+"/test");
JMXConnectorServer cs=
JMXConnectorServerFactory.newJMXConnectorServer(url,null,mbs);
cs.start();
...
where rmi is a "localhost:6665", an address of a rmiregistry created localy with command 'rmiregistry 6665'.
then, jmx manager code is:
...
JMXServiceURL url=
new JMXServiceURL("service:jmx:rmi:///jndi/rmi://"+rmi+"/test");
JMXConnector jmxc= JMXConnectorFactory.connect(url,null);
System.out.println("JMXConnector connected: "+jmxc.getConnectionId());
MBeanServerConnection mbsc= jmxc.getMBeanServerConnection();
...
where rmi is an address of the rmiregistry located on the machine where agent runs.
now, if both agent and manager run on the same machine, so that manager's rmi is also "localhost:6665" everything works fine. then, even jconsole may be used connecting through advanced tab's jmx url..
if agent and manager run on the different machines but on the same subnet, xxx.yyy.zzz.aaa and xxx.yyy.zzz.bbb, so that manager's rmi is now xxx.yyy.zzz.aaa:6665 everything works fine, too..
now, if agent and manager are running on the different machines and different subnets then manager's
JMXConnector jmxc= JMXConnectorFactory.connect(url,null);
returns after few minutes with an exception
java.rmi.ConnectException: Connection refused to host: agent.machine.ip.address; nested exception is:
java.net.ConnectException: Connection timed out
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:574)
at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:185)
at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:171)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:94)
at javax.management.remote.rmi.RMIServerImpl_Stub.newClient(Unknown Source)
at javax.management.remote.rmi.RMIConnector.getConnection(RMIConnector.java:2239)
at javax.management.remote.rmi.RMIConnector.connect(RMIConnector.java:271)
...
what am i doing wrong ?
thanx.

