Why Java RMI Callback doesn't work behind NAT router? -
i'm trying callback on java rmi simple program, , works ok in localhost , lan, have problems doing behind nat router.
i connection refused if server implementation extends unicastremoteobject
. if don't extends unicastremoteobject
, export object manually (unicastremoteobject.exportobject(services, 0);
), server action when client calls remote method, , when server calls callback method, gets connection timeout because phone call going private ip.
i bind service in registry this:
public class server { private static final string srvhost = "<<external ip>>"; private static registry registry; public static void main(string[] args) { system.setproperty("java.rmi.server.hostname", srvhost); system.setproperty("java.rmi.server.usecodebaseonly","false"); system.setproperty("java.security.policy","src/srv.policy"); if(system.getsecuritymanager()==null) system.setsecuritymanager(new rmisecuritymanager()); registry = locateregistry.createregistry(registry.registry_port); serverinterface services = new serverimpl(); registry.rebind("serverapi", services); } }
and client gets service:
public class client { private static final string srvhost = "localhost"; private static registry registry; private static clientinterface callback; public static void main(string[] args) { system.setproperty("java.security.policy", "src/cli.policy"); if(system.getsecuritymanager()==null) system.setsecuritymanager(new rmisecuritymanager()); registry = locateregistry.getregistry(srvhost, registry.registry_port); serverinterface services = (serverinterface) registry.lookup("serverapi"); callback = new clientimpl(); int ncallback = services.setclientinterface(callback); ... <<do_things>> } }
the method setclientinterface(...)
gets client object , stores in arraylist
.
i don't know what's problem. can help me?
all code published here:
policy files:
srv.policy - http://pastebin.com/ltsksg3r
cli.policy - http://pastebin.com/zqxaryt3
package: com.rmicallback.client
client.java - http://pastebin.com/xus04jzk
clientimpl.java - http://pastebin.com/sdqxmdzs
clientinterface.java - http://pastebin.com/s9pxt5vc
package: com.rmicallback.server
server.java - http://pastebin.com/cxqcwy1q
serverimpl.java - http://pastebin.com/nqdgpbpr
serverinterface.java - http://pastebin.com/npxdjgs1
java rmi router nat behind
No comments:
Post a Comment