You are correct to pick up the typos in my note. The syntax
that I got to bind was in fact "rmi//... rather than "rmi:// ...
As I have since read various sources, I have found the syntax for the argument of
bind and rebind variably as:
("rmi://host/name", obj) or ("//host/name", obj).
Further experimentation has shown that ANY of the following forms execute
without throwing an exception:
("rmi://host/name", obj), or
("//host/name", obj), or even
("rmi//host/name", obj) without the ':'
I have found that 'localhost' or '127.0.0.1' will NOT work for 'host' in the
above forms, whereas the IP address for the server or it's nickname from
/etc/hosts will work fine as the 'host' element. This all seems odd to me, I
must admit. I must also admit I have yet to get lookup() to work on an applet
downloaded from the server. If you have any insight into this I would be glad
to hear it! I suspect I'm missing something obvious here.
Here's the code that executes the rebind:
import java.rmi.*;
import java.rmi.server.*;
import java.net.*;
public class HelloImpl extends UnicastRemoteObject implements HelloInt {
public String name;
public HelloImpl (String s) throws RemoteException {
super();
name = s;
}
public String sayHello() throws RemoteException {
return "Hello World!";
}
public static void main (String args []) {
System.setSecurityManager (new RMISecurityManager());
try {
HelloImpl obj = new HelloImpl ("HelloServer");
System.out.println ("Attempting to rebind . . .");
Naming.rebind ("rmi://xxx.xxx.x.x/HelloServer", obj);
System.out.println ("Hello Server bound . . .");
}
catch (RemoteException re) {
System.out.println ("RemoteException in HelloImpl.main: " +
re.getMessage());
re.printStackTrace();
}
catch (MalformedURLException e) {
System.out.println ("MalformedURLException in HelloImpl.main:
" + e.getMessage());
e.printStackTrace();
}
}
}
This produces the "Attempting to rebind . . ." and "Hello Server bound . . ."
messages on the console as one would expect.
-DTB