aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes RMI service bind/lookup problem(Very freak!) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "RMI service bind/lookup problem(Very freak!)" Watch "RMI service bind/lookup problem(Very freak!)" New topic
Author

RMI service bind/lookup problem(Very freak!)

frank sun
Ranch Hand

Joined: Apr 11, 2003
Posts: 102
Hi, all
If sets the host name with a string starting number format , you can bind the service on any computer,and if running the RMI client on the same computer with server, you can set the host name with any other digital number format string to lookup. (the server port must be 1099)
the below is the detail, you could read the bold words only.
the signature of rebind in java.rmi.Naming is:
public static void rebind(String name, Remote obj) throws RemoteException, MalformedURLException
Comments:
name - a name in URL format (without the scheme component)
MalformedURLException - if the name is not an appropriately formatted URL
the signature of lookup in java.rmi.Naming is:
public static Remote lookup(String name) throws NotBoundException, MalformedURLException, RemoteException
Comments:
name - a name in URL format (without the scheme component)
MalformedURLException - if the name is not an appropriately formatted URL

Let's see this condition : ( server and client Running on the same computer)
1. sets the parameter of name in rebind with "1111"(or "1111A") , and any available port, and startup the server,
2. sets the parameter of name of in lookup with "2222"(or "2222B"), and any available port, starts up the client
3. freakly, the client can connect to the server and do any query and other operations.
4. and, if sets the host with the remote host name of IP address in remote or local client, it can connect to the server.
Please note, the server binds a different name from the name of lookup!!!
** of course, if the server sets the bind name with the local host name of IP, the remote clients can only use the host name or IP of the remote server to connect to, but the local client can use any name starting with number.
You will find that the application runs normally, I wonder:
1: the parameters of name in rebind and lookup should be a valid computer name/IP, right?
2: if parameters of name not a host, the server starts up in a local mode, and does not accept LAN request, only accept the local client request, even the binded name differs from the lookup name right?
3: since the server has the different binded name from the lookup name, why the server can accept the request?
3: are there any other similar situation like that?
4: should I specify this situation in the user guide or design choices?

In a word, if the server binds to a name with number start(eg,"12",or "12A"), the local client can connect to it with any other host name(eg,"23",or "34A"), even different port; but the remote client can use the server's host name or IP and the same port to connect to the server. the prerequisite is: the server port must be 1099, otherwise, all these freak things won't show up.

Please, I am crazy about that.
Regards!
Frank
[ May 26, 2003: Message edited by: frank sun ]
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11484
    
  94

Hi Frank,
Perhaps you could post some code? I cannot duplicate this.
Here is the code I tried:
Now I must have missed something from your post, because this gives me the error I expect:

Regards, Andrew


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
frank sun
Ranch Hand

Joined: Apr 11, 2003
Posts: 102
Thanks Andrew,
The below is my snippet code of service binding and lookup.
I guess there are no "//", ":", "/", in your argument of name in rebind() and lookup(), that's why they cannot run.(not sure)


-------------------------------------------------
I debug the java source of java.rmi.Naming, when I pass the argument of name of the rebind(), it parses all the host, whose name starts with number(not the IP), as an empty string.
I think that's why the above freak thing happens.
Here is the code snippet in java.rmi.Naming from the java source:

it parses the argument(service name) into this method, and it always prints out an empty string when the host name starting with number.
-----------------------------------------------
And, if sets the computer name starting with number, say "1234AB", and it only permits to use the port of 1099 to start up.
I did test these situation.
I am trying to look into the source of java.net.URI.
So, could you help to deep into the java source code to find the truth with me?
Best regards!
Frank
[ May 26, 2003: Message edited by: frank sun ]
[ May 26, 2003: Message edited by: frank sun ]
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11484
    
  94

Hi Frank,
could you help to deep into the java source code to find the truth with me
Sorry, no can do. My schedule this week is very tight (including submitting today / tomorrow and doing the exam on Thursday), and I leave for a weeks holiday on Saturday, so I have no room for slipage, and no spare cycles to look into this.
Good luck with it.
Regards, Andrew
frank sun
Ranch Hand

Joined: Apr 11, 2003
Posts: 102
Originally posted by Andrew Monkhouse:
Hi Frank,
Sorry, no can do. My schedule this week is very tight (including submitting today / tomorrow and doing the exam on Thursday), and I leave for a weeks holiday on Saturday, so I have no room for slipage, and no spare cycles to look into this.
Good luck with it.
Regards, Andrew

Thanks Andrew,
Congratuation in advance!
---------------------------------------------
The below is your code snippet of FrankRmi, I just
modified slightly.

---------------------------------------------
You'll find that it can run without any error.
that's what I wonder!
thanks!
Frank
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11484
    
  94

Hi Frank,
Yep, just put your modifications into my code, and ran it under JDK 1.4.0 on Linux - worked without problems.
I agree it is weird.
Do you have computers with hostnames like this?
i am not going to worry about it - I dont think we should have to cater for this in our assignments.
Regards, Andrew
frank sun
Ranch Hand

Joined: Apr 11, 2003
Posts: 102
Originally posted by Andrew Monkhouse:
Hi Frank,
Yep, just put your modifications into my code, and ran it under JDK 1.4.0 on Linux - worked without problems.
I agree it is weird.

Do you have computers with hostnames like this?

i am not going to worry about it - I dont think we should have to cater for this in our assignments.
Regards, Andrew

I am not sure all the computer's name do not start with a number.
The following is my finding on this problem, for your reference.
In the source code of java.rmi.Naming, it parses the argument of name in rebind and lookup:
URI uri = new URI(str)
and, uses this statement to get the Host and Port:

String host = uri.getHost();
int port = uri.getPort()

You can just test the argument of str in the constructor of URI.
when you input the str as "//1234A:2003/name", or any other
simular string with that, but only limits the host name starting with number.
the result of uri.getHost() always return null, and uri.getPort() always returns -1.
I think that's why the host name should not start with a number.
the below is from the comment of the getHost() in java.net.URI,It limits the name must begin with an alpha char.
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.
So, I guess I have to stop to look for the trouble by myself on this problem.
But I still wonder should I specify this in the user guide, what's your suggestion?
Regards!
Frank
[ May 27, 2003: Message edited by: frank sun ]
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11484
    
  94

Hi Frank,
But I still wonder should I specify this in the user guide, what's your suggestion?
I am not going to mention this - I dont think the problem is likely to occur in real life.
Regards, Andrew
frank sun
Ranch Hand

Joined: Apr 11, 2003
Posts: 102
Hi,Andrew
Thanks, I think I will add some statements in the user guide in the section of [Parameters configuration] : the host name must begin with an alpha character.
Thanks!
Frank
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: RMI service bind/lookup problem(Very freak!)