June 2001
Intermediate to advanced
888 pages
21h 1m
English
Content preview from Java CookbookBecome an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
Start your free trial



RMI Server
Problem
The client looks good on paper, but will be lonely without a server to talk to.
Solution
You need to write two parts for the server, an implementation class and a main method. These can be in the same class or separated for clarity.
Discussion
The server-side code has to do a bit more work; see the sidebar.
This implementation divides the server into the traditional two parts, a main program and an implementation class. It is just as feasible to combine these in a single class. The main program shown in Example 22-3 simply constructs an instance of the implementation and registers it with the lookup service.
Example 22-3. DateServer.java
package darwinsys.distdate; import java.rmi.*; public class DateServer { public static void main(String[] args) { // You may want a SecurityManager for downloading of classes: // System.setSecurityManager(new RMISecurityManager( )); try { // Create an instance of the server object RemoteDateImpl im = new RemoteDateImpl( ); System.out.println("DateServer starting..."); // Locate it in the RMI registry. Naming.rebind(RemoteDate.LOOKUPNAME, ...