java - How to make a RMI server work for both local clients (within the same network) and external clients -
i'm pretty new java , rmi, , decided try set own server chat client on home computer (just learning purposes, no real use intended it) . sum up, i'm using socket connection messages , rmi communication between server , client . problem i'm using router , want client work both external connections , internal connections (my laptop example- connected same router server).
my public ip is: 109.99.33.251
local ip adress is: 196.168.1.9
problem if set java.rmi.server.hostname to
- server local ip :
- everything works intended, when accessing server local machines.
- when accessing external machine, socket connects , rmi lookup throws connection refused: connection timed out. (i want mention i'm 99% sure port forwarding set both rmi (1099) , server (5000) )
- server public ip: works, external machines.
- when trying connect local machine local ip of server socket connects fine, rmiregistry lookup method fails.
- when connecting local machine public ip of server, neither rmiregistry nor socket connects.
guess it's problem router. think doesnt support nat loopback (accessing server lan component it's public ip) since never works me connect server it's public ip local machine, though port forwarding set correctly (it works when connecting externally both rmi , socket connections).
is there can make work?
edit: on server side, set system.setproperty("java.rmi.server.hostname","109.99.33.251");
after server starts , i: locateregistry.createregistry(1099);
bind object:
myremote stub= new communicator(); registry = locateregistry.getregistry(); registry.bind("comm", stub);
where myremote interface extends remote interface , communicator is:
public class communicator extends unicastremoteobject implements myremote { public communicator() throws remoteexception { super(registry.registry_port); system.out.println("i've created host"); } //the methods in myremote }`
sockets use:
serversocket serversock = new serversocket(5000); while(true) { socket clientsocket = serversock.accept(); clienthandler handler =new clienthandler(clientsocket); clients.add(handler); thread t = new thread(handler); t.start(); system.out.println("got connection"); }
client lookup: service=(myremote) naming.lookup("rmi://"+serverip+"/comm");
, socket connection socket socket=new socket(serverip,new integer(serverport));
serverip
holds either public ip of server, or local one, depending on case presented earlier. , serverport
5000
to make myself clear, want client work on both local , external machines, looking way bind remote objects , set connections make both work, if that's possible.
note: i'm sorry, i'm new networking , java , site, please don't mind mistakes make when asking questions. thank in advance!
final edit: i've contacted isp , said router has latest firmware version , doesn't support nat loopback.
unfortunately oracle/sun rmi implementation broken in respect. there unnecessary deep assumption there single ip address visible clients. have set java.rmi.server.hostname
public ip address outside nat, , inside clients have able use address.
Comments
Post a Comment