简体   繁体   English

当客户端计算机具有多个IP地址时,RMI服务器到客户端调用失败

[英]RMI Server to Client call fails when Client machine has more than one IP Address

First off, I'd love to post some real code for this question, but I can't because it's far too many lines. 首先,我想为这个问题发布一些真实的代码,但我不能,因为它太多了。 That said, here's my situation: 那就是说,这是我的情况:

Server Side 服务器端

I have an RMI Server that waits for Clients to connect and "register" themselves, so that the Server can make function calls on Clients. 我有一个RMI服务器等待客户端连接和“注册”自己,以便服务器可以在客户端上进行函数调用。 Basically, the server has a published function that works like the following pseudo-code: 基本上,服务器有一个已发布的函数,其作用类似于以下伪代码:

public class Server extends UnicastRemoteObject implements ServerInterface{
    public Server(){ /* Server publishes itself here */ }

    ...

    /** One of many methods visible to a remote Client */
    public void registerClient(Client c) throws RemoteException{
        //1. Make some remote calls on 'c' for book-keeping purposes
        //2. Store reference to c to make calls on it later
    }
}

Client Side 客户端

On Startup, the Client makes a call to Naming.lookup([url]) to get a stub to the Server that I'll call serverRef , then calls serverRef.registerClient(this) . 在启动时,客户端调用Naming.lookup([url])来获取服务器的存根,我将其称为serverRef ,然后调用serverRef.registerClient(this) The problem happens the first line of the server's registerClient(Client c) method. 问题发生在服务器的registerClient(Client c)方法的第一行。

Problem 问题

When the server makes its first remote method call to the Client inside the registerClient method, a RemoteException is thrown. 当服务器在registerClient方法内对Client进行第一次远程方法调用时,抛出RemoteException。 While client and server machines are on the same subnet, the client's machine has a secondary IP address. 当客户端和服务器计算机位于同一子网上时,客户端的计算机具有辅助IP地址。 So the IPs look something like this: 所以IP看起来像这样:

Server Machine IPs: 123.45.67.1 服务器机器IP: 123.45.67.1
Client Machine IPs: 123.45.67.2 , 192.168.67.2 客户机IP地址:123.45.67.2,192.168.67.2

The RemoteException that gets thrown during the Server's first remote call back to the client indicates that the Server is trying to connect to the Client's 192.168.67.2 address, which is what's causing the failure. 在服务器的第一次远程回调期间抛出的RemoteException指示服务器正在尝试连接到客户端的192.168.67.2地址,这是导致失败的原因。 The Server should be trying to connect to the 123.45.67.1 address. 服务器应该尝试连接到123.45.67.1地址。 I know that disabling the network interface that belongs to the second IP address would fix the problem, but this isn't really an option for me. 我知道禁用属于第二个IP地址的网络接口可以解决问题,但这对我来说不是一个真正的选择。

Is there any way to "tell" server-side RMI which IP address to connect on when opening a connection to a new client-side object stub? 在打开与新客户端对象存根的连接时,有没有办法“告诉”服务器端RMI连接哪个IP地址?

There are several possible solutions, including 有几种可能的解决方案,包括

  • write a custom client socket factory 编写自定义客户端套接字工厂

  • specify addresses in java.rmi.server.hostname property 在java.rmi.server.hostname属性中指定地址

    -Djava.rmi.server.hostname=ip_address

  • etc 等等

Check out this link: 看看这个链接:

These links are also useful: 这些链接也很有用:

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

相关问题 确定Java RMI调用的远程客户端IP地址 - Determine remote client IP address for Java RMI call 客户端拨打电话时RMI服务器ClassNotFoundException - RMI server ClassNotFoundException when client makes call Java RMI - 客户端到服务器的调用 - Java RMI - client to server call 如何使用 IP 地址和端口号连接到服务器套接字? (客户端运行在与服务器不同的机器上) - How do I connect to the server socket using the ip address and port number? (client is running on a different machine than server) 具有多个客户端的Java rmi服务器-一次仅接受一个客户端调用 - Java rmi server with multiple client - Only accept one client call at the time 获取Spring MVC中客户端机器的IP地址 - Get IP address of client machine in Spring MVC 使用java获取客户端计算机的ip地址 - Obtaining ip address of client machine using java Java RMI,当服务器不调用任何客户端方法时,服务器应如何管理客户端异常关闭? - Java RMI, how should server manage abnormal client shutdown, when it doesn't call any client method? RMI客户端方法调用 - RMI client method call RMI客户端/服务器 - 无法从客户端调用某些远程方法 - RMI client/server - cannot call some remote methods from client
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM