[Java] the RMI client cannot be connected when the server has two or more NICs.

Source: Internet
Author: User
Error Stack:
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

It is strange that the URL accessed by RMI is correct, but the IP address obtained from subsequent access is inaccessible from another of the dual-nic.

Perform a simple test on the local machine:
System. Out. println (unicastremoteobject. exportobject (new remote () {}, 0 ));
Output:
Proxy [remote, remoteobjectinvocationhandler [unicastref [liveref: [endpoint: [192.168.2.3: 2339] (local), objid: [0]
It indicates that the IP address of the object has been determined when it is not registered. After it is bound, the client will follow this IP address as shown in the figure below. There are two NICs on the server. If you find one, it will be over.
This method is useful for Distributed Object Registration, but it is relatively retarded when multiple IP addresses are involved. Sun's FAQ provides a simple answer:
Http://java.sun.com/j2se/1.5.0/docs/guide/rmi/faq.html#netmultihomed

One sentence:
System. setproperty ("Java. RMI. server. hostname", "192.168.2.3"); // we recommend that you load data from the configuration file.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.