Creating the Remote Interface

To create the client-server application using RMI, you need to create a remote interface that declares the business logic of the application. The file is a remote interface for the File Download application that defines the prototypes of the methods implemented by the file.

Listing 3-1 shows the contents of the file:

Listing 3-1: The File
start example
 /* Imports java.rmi package classes. */ import java.rmi.Remote; import java.rmi.RemoteException; /* Imports java.util package classes. */ import java.util.Vector; /* Interface FileRemote - This interface declares the remote methods. Methods: downloadFile() - Downloads the file from a remote location. displayList() - Displays the list of files stored in the server to the client. */ public interface FileRemote extends Remote  {    /* Declares downloadFile() method. */    public byte[] downloadFile(String filename) throws RemoteException;    /* Declares displayList() method. */    public Vector displayList() throws RemoteException; } 
end example

Download this Listing .

In the above code:

  • The FileRemote interface defines the methods to perform various operations of the File Download application. These methods include displayList() and downloadFile().

  • The displayList() method displays the file list to the client machine.

  • The downloadFile() method downloads the selected file from the remote machine.

Java InstantCode. Developing Applications Using Java NIO
Java InstantCode. Developing Applications Using Java NIO
Year: 2004
Pages: 55 © 2008-2017.
If you may any questions please contact us: