java - RMI seen from Internet but not from LAN -


this first post in stackoverflow, i'm trying implement chat using rmi i'm stuck, avoiding use of rmiregistry, binding on localhost, need accesible internet, ports forwarded, firewall down, , can retrieve through internet object, i've achived using

system.setproperty("java.rmi.server.hostname","ruso.89.x.ignorelist.com"); 

so nameserver.java binds ip, lose access through localhost, let me explain this. code nameserver.java

public class nameserver {    public static void main (string args [] )    {     string direscucha = "ruso.89.x.ignorelist.com";     int puertonombres = 5000;     try{          system.setproperty("java.rmi.server.hostname", direscucha);                   system.setproperty("java.security.policy", "c:\\users\\antonio\\desktop\\distributedchat\\myserver.policy");         system.setsecuritymanager(new rmisecuritymanager());         nameservice ns = new nameservice();         registry reg=locateregistry.createregistry(puertonombres);         reg.rebind("ns",ns);         while(true){}     }catch(exception e){         system.out.println(e);     }   } } 

this policy file:

grant { permission java.security.allpermission; permission java.net.socketpermission "ruso.89.x.ignorelist.com:*", "connect,resolve,accept"; permission java.net.socketpermission "localhost:*", "connect,resolve,accept"; permission java.net.socketpermission "127.0.0.1:*", "connect,resolve,accept"; }; 

then need chatserver.java run, takes ns , binds himself it, chatserver can found, problem when use outside lan can server running! when use localhost got exception

chatserver.java (snippet)

public void work () {     string direscucha = "ruso.89.x.ignorelist.com";             int puertonombres = 5000;     system.setproperty("java.rmi.server.hostname", direscucha); //binds public ip     system.setproperty("java.security.policy", "c:\\users\\antonio\\desktop\\distributedchat\\myclient.policy"); //marca la politica     system.setsecuritymanager(new rmisecuritymanager()); //ejecuta el rmisecuritymanager     try     {                                             string[] list = naming.list("//localhost:5000/"); //debugging         system.out.println("tamanyo: "+list.length);               for(int i=0; i<list.length; i++)                               system.out.println(list[i]);         nameservice_stub ns =  (nameservice_stub) naming.lookup("rmi://localhost:5000/ns");          ns.rebind (conf.getservername(), this);         system.out.println("servidor registrado::");     }     catch (java.rmi.connectexception e)     {         system.out.println (e);         system.exit(-1);                 }     catch (exception e)     {         system.out.println(e);         system.exit(-1);     } 

so when serverchat registered user can execute chatclient.java retrieve nameservice name of chatserver , connect, didn't got there yet because can't manage chatserver work. first though when seting hostname property localhost get's blocked mentioned, afterwards i've though may problem router nat, be?

exception:

java.rmi.connectexception: connection refused host: ruso.89.x.ignorelist.com; nested exception is: java.net.connectexception: connection refused: connect 

client , server policy files identical. used wireshark see happening, syn send , ack,rst recieved. i've burnt ideas, suggestions?

i've achived using

system.setproperty("java.rmi.server.hostname","ruso.89.x.ignorelist.com");

so nameserver.java binds ip

no doesn't. it's common misperception, incorrect. rmi binds serversockets 0.0.0.0 unless provide rmiserversocketfactory otherwise. effect of java.rmi.server.hostname embed value stub (essentially instead of value returned inetaddress.getlocalhost()).

   while(true){} 

you don't need smoke cpu doing that, need make registry reference static variable. rmi starts thread when export remote object prevent jvm exiting until unexport it. unexporting happens automatically when remote object garbage-collected, , static reference prevent that.

connection refused host: ruso.89.x.ignorelist.com

that may mean internal firewall won't let connect outwards host though it's own. or ruso.89.x.ignorelist.com has different, incorrect dns mapping inside network.


Comments

Popular posts from this blog

python - How to create a legend for 3D bar in matplotlib? -

java - Multi-Label Document Classification -

php - Dynamic url re-writing using htaccess -