COMP 310
Fall 2011

Lab08: Java RMI

Home  Info  Owlspace  Java Resources  Eclipse Resources

Remote Method Invocation

As the name implies, Java RMI is a mechanism to invoke methods on a remote machine and receive the results. A typical RMI application consists of a server, which makes remote objects available, and a client, which invokes methods on those remote objects.

In order for this to work, the client must be able to locate remote objects.  This is accomplished using the RMI registry.  Remote objects are registered in the registry by the server.  The client can then look up these objects in the registry.

Once the client has a reference to the remote object from the registry (called a stub), it must be able to communicate with it.  In Java RMI, this communication is handled seemlessly, and to the client, everything looks exactly as if a method were being invoked on a local object.

Getting the Example Code

The "hello world RMI" program is available in subversion.  You should create a new project and use the svn:externals property to add the following provided code into your project: https://svn.rice.edu/r/comp310/course/RMIHelloWorld/provided.

Networking and Firewalls

As discussed above, RMI works by having a server register available remote objects.  Clients can then look up and access those remote objects.  This requires the client to know two things about the server.

The first is the IP address of the server.  An IP address is a 32-bit number (usually written in dotted decimal notation, i.e., 192.168.1.1) that uniquely identifies hosts in the Internet.

The second is the port on the server that corresponds to the RMI registry. A network server may be running several services at once (i.e., a web server, an e-mail server, a Java RMI server, etc.). Each service is associated with a unique 16-bit port number on that machine.  Common services use "well known port numbers." For instance, most all web servers listen on port 80. But, a service can associate itself with any port.

The combination of an IP address and a port number provides an unambiguous address of a particular service on a server. Clients can then use that address/port combination to access that service.

As you well know, Windows is susceptible to a large number of malicious attacks over the network. So, all Windows machines typically run firewall software that blocks access to almost all network ports. This prevents attackers from gaining entrance to the machine to access services that you may not even know are running.  In order to allow others to access your Java RMI server, we must tell the firewall to allow access to the ports we will be using.  For this class we will be using ports in the range of 2001-2002 and 2099-2102.

Opening ports on Firewalls:

  1. Type "windows firewall" in the Start menu search box
  2.  Click on "Inbound Rules" and then click "New Rule..."
  3.  For the Rule Type, choose "Port" and click "Next".
  4. You will want to allow all 6 ports (2001-2002) plus (2099-2102) for TCP access.
  5. Click "Next" twice, taking the defaults, until it asks for a name, then input a useful name, like "Comp310 RMI ports"
  6. Click "Finish"

For those that are running Macs as of OS X 10.6+, which is any machine released within the last couple of years, you can't not open arbitrary ports as you can on Windows. Instead, you can only allow ports to be via the application layer. So to get this working you will have to perform the following steps:

  1. First get the path name to the JRE that is being used with Eclipse:

    1. Open eclipse preferences. 

    2. Go to Java/Installed JREs and find the one that is checked and copy that location under the location column.

  2. Open Apple's System Preferences.

  3. Select the "Security & Privacy".

  4. Select the Firwall tab.

  5. Click on the Advanced button. This will open a sub menu with a table of allowed programs that can receive inbound connections through any arbitrary number of ports.

  6. Under the table press the '+' button.

  7. An open file submenu will pop up. To enter the path press "Shift-Command-G" and a "Go To Folder" window will popup. In this window enter the path name from the one that was copied from Eclipse in step 1.

  8. The open file submenu will open that directory. From there select the "bin" subdirectory, select the "java" unix executable, and select the "Add" button on the bottom right.

  9. Basically, this allows any Java program that requires ports to be open through the JVM. So as a safety measure, the JVM added to the table from step 5 should be removed after the project and future projects are complete.

Using the RMI Hello World Program

We will walk through the code of both the client and server and discuss how they work.  Then you will run both programs on your machine.  Finally, you will access a server running on someone else's machine.

More details on running the code can be found on Friday's lecture page.

 

Compute Engine Project

If we have time, we will try to get the demo of the HW07 Compute Engine project operational.

 

 


© 2011 by Stephen Wong and Scott Rixner