`
dd2086
  • 浏览: 34889 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

RMI客户端在服务器双网卡或者多网卡情况下无法连接问题

阅读更多
出错堆栈:
org.springframework.remoting.RemoteConnectFailureException: Cannot connect to remote service [rmi://192.168.2.61/Service]; nested exception is java.rmi.ConnectException: Connection refused to host: 192.168.7.11; nested exception is:
java.net.ConnectException: Connection timed out: connect

很奇怪,rmi访问的url是对的,但是后续的访问得到的IP却是双网卡中的另外一个无法访问的。

在本机做个简单试验:
  System.out.println(UnicastRemoteObject.exportObject(new Remote(){},0));
输出:
Proxy[Remote,RemoteObjectInvocationHandler[UnicastRef [liveRef: [endpoint:[192.168.2.3:2339](local),objID:[0]]]]]
说明对象在没有注册出去的时候其IP就已经决定,绑定出去以后客户端就按照这个IP按图索骥。Server端有两个网卡,乱找一个就Over了。
这种方式对分布式对象注册很有用,但是碰到多IP的情况下就比较弱智了。sun的faq上给出一个简单答案:
http://java.sun.com/j2se/1.5.0/docs/guide/rmi/faq.html#netmultihomed

一句话:
  System.setProperty("java.rmi.server.hostname","192.168.2.3");//建议从配置文件加载。


//解决连接超时
System.setProperty("sun.rmi.transport.tcp.responseTimeout", new Integer(Integer.MAX_VALUE).toString());
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics