RMI setup

RMI setup locally

From testing Spring 1999 - newest RMI notes specify most of this explicitly
So, consider this:
Common attempts, errors and misconceptions
and just plain playing around
My files are in 
expert:/user/faculty/amk/www/foo/cscijava/network> ls
Account.class     HelloImpl.java~   index.html        showthem
Hello.html        Receipt.class     index.html~       tcpClient.class
Hello.html~       examples          javalab3.html     tcpClient.java
Hello.java        fileServer.class  readFile.class    tcpClient.java~
HelloApplet.java  fileServer.java   readFile.java     tcpServer.class
HelloImpl.java    fileServer.java~  readFile.java~    tcpServer.java
> diff Hello.html~ Hello.html < <applet codebase="../.." < code="examples.hello.HelloApplet" --- > <applet codebase="../.." code="examples.hello.HelloApplet.class" > diff HelloImpl.java~ HelloImpl.java < Naming.rebind("//myhost/HelloServer", obj); --- > Naming.rebind("//expert.ecst.csuchico.edu/HelloServer", obj); OK ..I just showed those so you could see what was there first... the ~ files were not used.

Now, this is interesting that they have us use this, since in code for the client, we do

Hello obj = (Hello)Naming.lookup("//" + getCodeBase().getHost() + "/HelloServer"); Here, if I add this line System.out.println("getCodeBase().getHost() is " + getCodeBase().getHost()); then output is getCodeBase().getHost() is If I have <applet codebase="expert.ecst.csuchico.edu/~amk/foo/cscijava/network" code="examples.hello.HelloApplet" We again get no output.
With <applet codebase="http://www.ecst.csuchico.edu/~amk/foo/cscijava/network" code="examples.hello.HelloApplet" and System.out.println("getCodeBase().getHost() is " + getCodeBase().getHost() +getCodeBase().getFile()); we get getCodeBase().getHost() is www.ecst.csuchico.edu/~amk/foo/cscijava/network/ Actually, this all makes sense since the codebase is the applet's codebase so it does need to be a web server ... or a file...but their code in the Client class does not make much sense unless we could run our server for RMI on the web server. Specifically, what we wanted here was a particular machine since we cannot run our rmi servers stuff on the web server.

This makes sense then, why what happens below happens...

expert:/user/faculty/amk/www/foo/cscijava/network/examples/hello> ls
Hello.class           HelloApplet.class     HelloImpl_Skel.class
Hello.html            HelloImpl.class       HelloImpl_Stub.class

Start the RMI registry
expert:/user/faculty/amk/www/foo/cscijava/network> rmiregistry &
[1]     29848
expert:/user/faculty/amk/www/foo/cscijava/network> jobs
[1] +  Running                 rmiregistry &
Since the server is at expert.ecst.csuchico.edu, I will run the client elsewhere - say on Molly (my SUN at home) java -Djava.rmi.server.codebase=http://expert.ecst.csuchico.edu/~amk/www/foo/cscijava/network/ examples.hello.HelloImpl

system responds with

HelloServer bound in registry

Happy with this so try to start applet on Molly:

appletviewer Hello.html

HelloApplet exception: Connection refused to host: [molly:1099]; nested exception is: 
        java.net.ConnectException: Connection refused
java.rmi.ConnectException: Connection refused to host: [molly:1099]; nested exception is: 
        java.net.ConnectException: Connection refused
        at sun.rmi.transport.tcp.TCPChannel.openSocket(TCPChannel.java:240)
        at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:125)
        at sun.rmi.server.UnicastRef.newCall(UnicastRef.java:73)
        at sun.rmi.registry.RegistryImpl_Stub.lookup(RegistryImpl_Stub.java:86)
        at java.rmi.Naming.lookup(Naming.java:60)
        at examples.hello.HelloApplet.init(HelloApplet.java:10)
        at sun.applet.AppletPanel.run(AppletPanel.java:287)
        at java.lang.Thread.run(Thread.java)

Now, if I run both the client and the server on the same machine, the above code works. The above code has in the client

So, I try the client and server on different machines...and it gives error above, unless change the client to

As far as I understand, the use of the system property (set with -D option on the command line or inside a program) java.rmi.server.codebase is used to identify the codebase for the RMIClassLoader. If there are no remote classes that will be loaded, this is not needed...?.

By default, the client would try to connect to a server on the local machine


In order for the RMIClassloader to work, you need to specify the java.rmi.server.codebase property when you run the bootstrapping program so that the loadClass method will use this URL to load the class. For example: Instead of relying on the property, you can supply your own URL: Once the client is started and has control, all classes needed by the client will be loaded from the specified URL. This bootstrapping technique is exactly the same technique Java uses to force the AppletClassLoader to download the same classes used in an applet.

If the client and the server are on the same computer (or cross-mounted?), the code base can be a file URL. However, if the client and server are on different computers, a Web server is necessary to provide a host for the class files, and the URL should target this Web server Without this bootstrapping technique, all the classes directly referenced in the client code must be available through the local CLASSPATH on the client, and the only Java classes that can be loaded by the RMIClassLoader over the net are classes that are not referred to directly in the client program; these classes are stubs, skeletons, and the extended classes of arguments and return values to remote method invocations.


Note compiling for a class in a package

javac -d . HelloApplet.java and running a class in a package

java example.hello.HelloImpl