Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/322.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java RMI应用程序在LAN中不工作_Java_Rmi - Fatal编程技术网

Java RMI应用程序在LAN中不工作

Java RMI应用程序在LAN中不工作,java,rmi,Java,Rmi,我有一个简单的RMI应用程序,当我试图在LAN中运行它时,它不起作用,我的类如下: public interface HelloInterface extends Remote { public String say() throws RemoteException; } 请帮助我使此应用程序在局域网中工作。您确定防火墙允许您连接吗?我必须关闭服务器上的防火墙,并关闭客户端连接。您是否阅读了教程?在运行应用程序之前是否启动了rmi注册表?如果您没有在应用程序中以编程方式启动它,

我有一个简单的RMI应用程序,当我试图在LAN中运行它时,它不起作用,我的类如下:

public interface HelloInterface extends Remote {

    public String say() throws RemoteException;
}




请帮助我使此应用程序在局域网中工作。

您确定防火墙允许您连接吗?我必须关闭服务器上的防火墙,并关闭客户端连接。

您是否阅读了教程?在运行应用程序之前是否启动了rmi注册表?如果您没有在应用程序中以编程方式启动它,则需要从命令行手动启动它。
public class Hello extends UnicastRemoteObject implements HelloInterface {

    private String message;

    public Hello(String msg) throws RemoteException {
        message = msg;
    }

    @Override
    public String say() throws RemoteException {
        return message;
    }
}
public class RmiServer {

    public static void main(String[] argv) {
        try {
            Naming.rebind("Hello", new Hello("Hello, world!"));
            System.out.println("Hello Server is ready.");
        } catch (Exception e) {
            System.out.println("Hello Server failed: " + e);
        }
    }
}
public class TestRMI {

    public static void main(String[] argv) {
        try {

            HelloInterface hello =  (HelloInterface) Naming.lookup("rmi://192.168.*.*/Hello");
            System.out.println(hello.say());
        } catch (Exception e) {
            System.out.println("HelloClient exception: " + e);
        }

        try {

        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}