Thank you for your reply and I'm sorry I did not reply sooner but I had a crisis to deal with.
I see I was not clear enough in my initial problem statement. The key to reproducing the behavior I observed is to use an IP address of the form "12345". What the numbers are does not seem to matter but it is important that you do not put it in the form of 12.34.5.0.
I compiled and ran your code on my system and when I did I got the same results that you did when you used:
String name = "rmi://" + "12.22.56.210" +":"+1099+"/remotemethod";
However I changed your code to use a name string as shown below: (Notice the IP address is "12345".
String name = "rmi://" + "12345" +":"+1099+"/remotemethod";
inter inte = (inter)Naming.lookup(name);
System.out.println(inte.meth("Rakesh"));
then your client program automatically defaults to the local host rather than throwing an exception!
Now I also posted this my observations on this behavior on Sun's RMI forum on javasoft.com. I got a most excellent reply from a RMI guru.
Re: Bizzare behavior with RMI using the localhost
Author: nunoo
In Reply To: Re: Bizzare behavior with RMI using the localhost
Feb 25, 2003 4:38 PM
Reply 3 of 4
Hi, there.
lookup uses URI parsing so the fact that your using numbers being equivalent to localhost seems to be due to the fact that that is an invalid host according to the javadocs for the getHost primitive attached below(marked the most important parts). In this case returning null is interpreted as absent , therefore => localhost. Nothing about the port! Maybe you can take it from here. Seems you'll have to make some user input validation yourself, in your application. Hope I haven't missed anything.
Good luck.
Nuno
-----------------------------
getHost
public String getHost()Returns the host component of this URI.
The host component of a URI, if defined, will have one of the following forms:
A domain name consisting of one or more labels separated by period characters ('.'), optionally followed by a period character. Each label consists of alphanum characters as well as hyphen characters ('-'), though hyphens never occur as the first or last characters in a label.
********************************************************************
The last, or only, label in a domain name begins with an alpha character.
********************************************************************
A dotted-quad IPv4 address of the form digit+.digit+.digit+.digit+, where no digit sequence is longer than three characters and no sequence has a value larger than 255.
An IPv6 address enclosed in square brackets ('[' and ']') and consisting of hexadecimal digits, colon characters (':'), and possibly an embedded IPv4 address. The full syntax of IPv6 addresses is specified in RFC 2373: IPv6 Addressing Architecture.
The host component of a URI cannot contain escaped octets, hence this method does not perform any decoding.
Returns:
The host component of this URI, or null if the host is undefined.
*******************************************
I think that Naming.lookup() should throw an exception if I feed it a garbage string no matter what that string may contain. Perhaps I'm mistaken but I don't think Naming.lookup() should ever "automatically" default to local system.
I'm going to submit this to Sun as a
java bug.
James