为什么java rmi继续连接到127.0.1.1。当ip是192.168.X.X? [英] Why does java rmi keep connecting to 127.0.1.1. When ip is 192.168.X.X?

查看:365
本文介绍了为什么java rmi继续连接到127.0.1.1。当ip是192.168.X.X?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个java rmi应用程序,我只是这样做:

I have a java rmi application i simply do:

客户:

Registry registry = LocateRegistry.getRegistry("localhost");
costApi = (CostApi) registry.lookup("server.CostApi");

当我在localhost托管服务器时,一切正常。当我在另一台具有本地网络的计算机上启动相同的程序时,在192.168.xx并更改为:

Everything works fine when I host the server at localhost. When I start the same program at another machine withing the local network, at 192.168.x.x and change to:

客户端:

Registry registry = LocateRegistry.getRegistry("192.168.x.x");
costApi = (CostApi) registry.lookup("server.CostApi");

它不再起作用而且失败并出现一个非常奇怪的错误:

it does not work anymore and it fails with a very strange error:

java.rmi.ConnectException: Connection refused to host: 127.0.1.1; nested exception is: 
    java.net.ConnectException: Connection refused
    at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:619)
    at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:216)
    at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:202)
    at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:129)
    at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(RemoteObjectInvocationHandler.java:194)
    at java.rmi.server.RemoteObjectInvocationHandler.invoke(RemoteObjectInvocationHandler.java:148)
    at com.sun.proxy.$Proxy0.dataCost(Unknown Source)
    at billing.data.DataBiller.performBilling(DataBiller.java:57)
    at billing.data.DataBiller.consumeMessage(DataBiller.java:46)
    at general.templates.RabbitWorker.run(RabbitWorker.java:124)
    at java.lang.Thread.run(Thread.java:744)
Caused by: java.net.ConnectException: Connection refused
    at java.net.PlainSocketImpl.socketConnect(Native Method)

我甚至没有尝试连接到127.0.1.1但是到192.168.xx,我该如何解决?我更喜欢只使用java代码而不是用配置文件修改我的机器。我正在使用linux

I'm not even trying to connect to 127.0.1.1 but to 192.168.x.x, how do I solve this? I prefer to use java code only and not modify my machine with config files. I'm using linux

推荐答案

这通常是由于配置错误造成的。检查 / etc / hosts 文件以确保:

This is usually caused by a misconfiguration. Check your /etc/hosts file to ensure that:


  • localhost映射到127.0 .0.1

  • 您的真实主机名映射到您的真实主机地址

一些Linux发行版已知让这个回到前面。

Some Linux distributions are known to have this back to front.

如果问题仍然存在,请尝试设置 java.rmi.server.hostname at服务器到客户端在执行远程方法调用时应使用的IP地址。它需要在导出任何远程对象之前设置,包括注册表。

If the problem persists, try setting java.rmi.server.hostname at the server to the IP address the client should use when executing remote method calls. It needs to be set before you export any remote objects, including the Registry.

问题是由存根中嵌入的IP地址引起的,最终来自类似 InetAddress.getLocalAddress(),,如上所述是错误的。它被 java.rmi.server.hostname覆盖。

The problem is caused by the IP address embedded in the stub, which ultimately comes from something like InetAddress.getLocalAddress(), which is fallible as above. It is overridden by java.rmi.server.hostname.

这是 FMI常见问题解答中的第A.1项,但请注意该项目是mistitled。在 lookup()期间不会发生这种情况,当您在生成的存根上调用远程方法时会发生这种情况。

This is item A.1 in the FMI FAQ, but note that the item is mistitled. It doesn't happen during lookup(), it happens when you call a remote method on the resulting stub.

这篇关于为什么java rmi继续连接到127.0.1.1。当ip是192.168.X.X?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆