Fix: RMI no localhost

This commit is contained in:
rubenpirreram
2026-05-05 19:26:33 +02:00
parent 836ed59c4c
commit cbe6447b75
@@ -26,7 +26,7 @@ import java.rmi.*;
* Server RMI. Exposes a method to join the game and one to execute an event. * Server RMI. Exposes a method to join the game and one to execute an event.
*/ */
public class RMIServer extends UnicastRemoteObject implements IGameServer { public class RMIServer extends UnicastRemoteObject implements IGameServer {
private String host;
/** Server game's controller */ /** Server game's controller */
private GameController controller; private GameController controller;
@@ -60,11 +60,12 @@ public class RMIServer extends UnicastRemoteObject implements IGameServer {
* @param playerList The player's usernames list * @param playerList The player's usernames list
* @throws RemoteException if an RMI error occurs * @throws RemoteException if an RMI error occurs
*/ */
public RMIServer(GameController controller, int nPort, BlockingQueue<NetworkEvent> actionQueue,LimitedList<String> playerList) throws RemoteException { public RMIServer(GameController controller, int nPort, BlockingQueue<NetworkEvent> actionQueue,LimitedList<String> playerList,String host) throws RemoteException {
this.controller = controller; this.controller = controller;
this.nPort = nPort; this.nPort = nPort;
this.actionQueue = actionQueue; this.actionQueue = actionQueue;
this.playerList = playerList; this.playerList = playerList;
this.host = host;
} }
@@ -249,9 +250,7 @@ public class RMIServer extends UnicastRemoteObject implements IGameServer {
*/ */
public boolean start() { public boolean start() {
try { try {
String ip = InetAddress.getLocalHost().getHostAddress(); System.setProperty("java.rmi.server.hostname", host); // o il tuo IP/hostname
System.out.println("Starting RMI Server on IP: " + ip);
System.setProperty("java.rmi.server.hostname", "10.8.0.3"); // o il tuo IP/hostname
registry = LocateRegistry.createRegistry(nPort); registry = LocateRegistry.createRegistry(nPort);
registry.rebind("RMIGameServer", this); registry.rebind("RMIGameServer", this);
System.out.println("RMI Server started on port: "+nPort); System.out.println("RMI Server started on port: "+nPort);