Java RMI-在不同计算机上运行的服务器和客户端会引发ConnectException:操作超时

我正在编写一个Java RMI程序,该服务器和客户端在不同的计算机上运行。

当我在服务器和客户端之间调用远程方法时,就会发生问题。当服务器和客户端都在同一台计算机上运行时,这些远程方法很好用,但是当服务器和客户端在不同计算机上工作时,它们花费的时间过长而导致操作超时错误,因此它们无法工作。

服务器端代码:

public class ServerImplementation extends UnicastRemoteObject implements Server {

    public static void init() {
        System.setProperty("java.rmi.server.hostname","172.2x.xx.xx");
        Registry registry = LocateRegistry.createRegistry(1099);
        registry.rebind("Server",new ServerImplementation());
        ...
    }
    ...
    @Override
    public void serverSideMethod() throws RemoteException {
        ...
        someclientObject.clientSideMethod();
    }
}

客户端代码:

public class ClientImplementation extends UnicastRemoteObject implements Client {

    public static void main(String args[]) {
        Registry registry = LocateRegistry.getRegistry("172.2x.xx.xx",1099);
        Server server = (Server) registry.lookup("Server");
        ...
    }
    ...
    @Override
    public void clientSideMethod() throws RemoteException { ... }
}

服务器端的错误堆栈跟踪:

java.rmi.connectexception: Connection refused to host: 127.0.1.1; nested exception is: 
    java.net.connectexception: Operation timed out
    at java.rmi/sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:619)
    at java.rmi/sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:209)
    ...
    at some_package.ServerImplementation.serverSideMethod(ServerImplementation.java:89)

我已在所有计算机上禁用了防火墙。地址172.2x.xx.xx是我的IP地址。谢谢!

wuhao1972 回答:Java RMI-在不同计算机上运行的服务器和客户端会引发ConnectException:操作超时

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3023863.html

大家都在问