简体   繁体   English

RMI服务器连接拒绝托管:#############; 嵌套的异常是:java.net.ConnectException:连接被拒绝:connect

[英]RMI Server Connection refused to host: ############ ; nested exception is: java.net.ConnectException: Connection refused: connect

I'm making my first RMI server (also including it in a project I'm working on). 我正在制作我的第一台RMI服务器(也将其包含在我正在从事的项目中)。 This is my error: 这是我的错误:

Exception in thread "main" java.rmi.ConnectException: Connection refused to host: 192.168.11.1;
nested exception is:
java.net.ConnectException: Connection refused: connect

This is the 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 is the Server class dont pay attention to all the FILEREADING stuff 这是Server类,不要关注所有FILEREADING的东西

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 i = 0; i < 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 is the interface IServidor 这是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 this utils class to set the classpath (saw in a tutorial) 我使用此utils类设置类路径(在教程中已看到)

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 already "javaw rmiregistry" in the cmd.... so... i dont know what to do. 我已经在cmd中“ javaw rmiregistry”了。...所以……我不知道该怎么办。 please, help me out. 请帮帮我。

Using win8.1... 使用win8.1 ...

At the very end of your question you said you are running Windows 8.1. 在问题的最后,您说您正在运行Windows 8.1。 Starting with Windows 7, the firewall is enabled by default. 从Windows 7开始,默认情况下启用防火墙。 My money is on the firewall blocking traffic to your RMI service. 我的钱在防火墙上,这阻止了流向您的RMI服务的流量。

You have a couple options: 您有两种选择:

  • Use the loopback address (127.0.0.1 for IPv4 and ::1 for IPv6) 使用回送地址(对于IPv4使用127.0.0.1,对于IPv6使用:: 1)
  • Unblock the application in the firewall 取消阻止防火墙中的应用程序
  • Unblock the port in the firewall 解除阻止防火墙中的端口
  • Turn off the firewall completely (not recommended) 完全关闭防火墙(不建议)

The Windows Firewall prefers you to open ports on an application by application basis. Windows防火墙希望您根据应用程序在应用程序上打开端口。 It's a lot easier to do that than it is to open the port yourself. 这样做比自己打开端口要容易得多。 I recommend managing it this way as it's a lot easier to work with. 我建议以这种方式进行管理,因为它更容易使用。 If it's a one-time set up, then you can unblock the application by going through your control panel, in the "System and Security Section" you should see the "Firewall" options. 如果是一次性设置,则可以通过控制面板来取消阻止该应用程序,在“系统和安全性”部分中,您应该看到“防火墙”选项。 One of the options is "Allow a program through Windows firewall". 选项之一是“允许程序通过Windows防火墙”。 You should also be able to find it by searching for the window firewall and finding the same option on the left hand commands. 您还应该能够通过搜索窗口防火墙并在左侧命令中找到相同的选项来找到它。

If you want to automate the process, for example in an install script, you can manage the firewall through the command line . 如果要自动化该过程(例如在安装脚本中),则可以通过命令行管理防火墙 For quick reference: 快速参考:

netsh advfirewall firewall add rule name="Secure App" dir=in action=allow program="C:\Program Files\SecureApp.exe" enable=yes

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Eclipse 4.23.0 连接拒绝主机:localhost; 嵌套异常是:java.net.ConnectException:连接被拒绝:连接 - Eclipse 4.23.0 Connection refused to host: localhost; nested exception is: java.net.ConnectException: Connection refused: connect RMI(java.net.ConnectException:连接被拒绝:连接) - RMI(java.net.ConnectException: Connection refused: connect) 连接被拒绝:连接; 嵌套异常是 java.net.ConnectException:连接被拒绝:连接 - Connection refused: connect; nested exception is java.net.ConnectException: Connection refused: connect Java 中的 ssh 异常:java.net.ConnectException:连接被拒绝:连接 - ssh Exception in Java: java.net.ConnectException: Connection refused: connect Tomcat异常 - java.net.ConnectException:连接被拒绝:连接 - Tomcat exception - java.net.ConnectException: Connection refused: connect 如何捕获“ java.net.ConnectException:连接被拒绝:connect”异常 - How to catch a “java.net.ConnectException: Connection refused: connect” exception java.rmi.ConnectException:连接拒绝主机:192.168.1.8; 嵌套的异常是: - java.rmi.ConnectException: Connection refused to host: 192.168.1.8; nested exception is: Tomee服务器:java.net.ConnectException:连接被拒绝:connect - Tomee Server :java.net.ConnectException: Connection refused: connect 无法连接到 Eureka 服务器。 异常:java.net.ConnectException:连接被拒绝:连接 - Cannot connect to Eureka server. Exception: java.net.ConnectException: Connection refused: connect 尝试连接到RMI注册表,但得到java.net.ConnectException:连接被拒绝:connect - Trying to connect to RMI Registry but getting java.net.ConnectException: Connection refused: connect
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM