COMP 310
|
Lab08: Java RMI |
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.
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.
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:
Windows: If you are using Windows Firewall (you probably are), then you need to open it. For Windows 7:
Mac: On many Macs, the firewall is turned off. If the firewall is turned on, do the following for OS X 10.6+:
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:
First get the path name to the JRE that is being used with Eclipse:
Open eclipse preferences.
Go to Java/Installed JREs and find the one that
is checked and copy that location under the location column.
If you are using a different firewall program or operating system, you will need to figure out how to allow TCP access to those four ports.
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.
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