11.7. Creating an RMI Client
Writing a client that uses an RMI service is easy compared with writing the service itself. The client needs only to obtain an object reference to the remote interface, and doesn't need to be concerned with how messages are sent or received or the location of the service. To find the service initially, a lookup in the RMI registry is made, and after that, the client can invoke methods of the service interface just as if it were a local object. The next example demonstrates how to turn a remote lightbulb on and off.
Code for LightBulbClient
import java.rmi.*; // Chapter 11, Listing 4 public class LightBulbClient { public static void main(String args[]) { System.out.println ("Looking for light bulb service"); try { ...
Get Java™ Network Programming and Distributed Computing now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.