RMI Server Connection refused to host: ############ ; nested exception is: java.net.ConnectException: Connection refused: connect -
i'm making first rmi server (also including in project i'm working on). error:
exception in thread "main" java.rmi.connectexception: connection refused host: 192.168.11.1; nested exception is: java.net.connectexception: connection refused: connect
this main:
import java.rmi.remote; import java.rmi.registry.locateregistry; import java.rmi.registry.registry; import java.rmi.server.unicastremoteobject; public class mainservidor { public static void main(string[] args) throws exception{ utils.setcodebase(iservidor.class); servidor_cubo servidor = new servidor_cubo(); iservidor remote = (iservidor)unicastremoteobject.exportobject(servidor, 8888); registry registry = locateregistry.getregistry(); registry.rebind("retoaleatorio", remote); system.out.println("servidor corriendo, presione enter para terminar"); system.in.read(); registry.unbind("retoaleatorio"); unicastremoteobject.unexportobject(servidor, true); } }
this server class dont pay attention filereading stuff
import java.io.file; import java.io.filenotfoundexception; import static java.lang.math.abs; import java.rmi.remoteexception; import java.util.arraylist; import java.util.hashmap; import java.util.map; import java.util.random; import java.util.scanner; /** * * @author emmanuel */ public class servidor_cubo implements iservidor { arraylist<reto> arrayretos; map<integer,string> mapajugadores_integer = new hashmap<integer,string>(); map<string,integer> mapajugadores_string = new hashmap<string,integer>(); public static int sesion = abs(new random().nextint()); @override public int agregarusuarionuevo(string nombre) throws remoteexception { int id = sesion++; mapajugadores_integer.put(id, nombre); mapajugadores_string.put(nombre, id); return id; } @override public integer autenticar(string nombre){ return mapajugadores_string.get(nombre); } @override public string traerretoaleatorio(int num){ return leerarchivomovimientos(num); } public void agregarganador(string nombre, int mov,int num){ int id = mapajugadores_string.get(nombre); } public void cargarservidor( ){ file freto = new file ("d:/repos/rubikfx-master/retos/listadoderetos.txt"); //ingresa ruta del .txt de retos file fjugadores = new file("d:/repos/rubikfx-master/retos/jugadores.txt"); //ingresa ruta del .txt de jugadores scanner scanreto; scanner scanjugador; try { system.out.println("si funcionaaa!!!"); scanreto = new scanner(freto); scanjugador = new scanner(fjugadores); arraylist<reto> retos = new arraylist<>(); while(scanreto.hasnext()){ reto reto = new reto(); arraylist<jugador> lista = new arraylist<>(); reto.setreto(scanreto.nextline()); string[] datoreto = scanjugador.nextline().split(";"); for(int = 0; < datoreto.length; i++ ){ jugador jug = new jugador(); string str = datoreto[i]; string[] datosjugador = str.split(","); jug.setnombre(datosjugador[0]); //int foo = integer.parseint("1234"); jug.setid (integer.parseint(datosjugador[1])); jug.setmovimientos(integer.parseint(datosjugador[2])); lista.add(jug); } reto.setganadores(lista); retos.add(reto); } } catch (filenotfoundexception ex) { system.out.println("no funciona!!!"); } }
this interface iservidor
package servidor_cubo; import java.rmi.remote; import java.rmi.remoteexception; public interface iservidor extends remote { public integer autenticar(string nombre) throws remoteexception; public int agregarusuarionuevo(string nombre) throws remoteexception; public string traerretoaleatorio(int num) throws remoteexception; }
i use utils class set classpath (saw in tutorial)
public class utils { public static final string codebase = "java.rmi.server.codebase"; public static void setcodebase(class<?> c) { string ruta = c.getprotectiondomain().getcodesource() .getlocation().tostring(); string path = system.getproperty(codebase); if (path != null && !path.isempty()) { ruta = path + " " + ruta; } system.setproperty(codebase, ruta); } }
i "javaw rmiregistry" in cmd.... so... dont know do. please, me out.
using win8.1...
at end of question said running windows 8.1. starting windows 7, firewall enabled default. money on firewall blocking traffic rmi service.
you have couple options:
- use loopback address (127.0.0.1 ipv4 , ::1 ipv6)
- unblock application in firewall
- unblock port in firewall
- turn off firewall (not recommended)
the windows firewall prefers open ports on application application basis. it's lot easier open port yourself. recommend managing way it's lot easier work with. if it's one-time set up, can unblock application going through control panel, in "system , security section" should see "firewall" options. 1 of options "allow program through windows firewall". should able find searching window firewall , finding same option on left hand commands.
if want automate process, example in install script, can manage firewall through command line. quick reference:
netsh advfirewall firewall add rule name="secure app" dir=in action=allow program="c:\program files\secureapp.exe" enable=yes
Comments
Post a Comment