Creating the File Server


The FileServer.java file contains the main function of the file server. The file server binds the remote object to the RMI registry. So, any authorized client can access the remote objects.

Listing 3-4 shows the content of the FileServer.java file:

Listing 3-4: The FileServer.java
start example
 /* Imports java.io package classes. */ import java.io.*; /* Imports java.rmi package classes. */  import java.rmi.*; /* class FileServer - Creates the RMI server that registers all the remote objects. Method: main() - Starts the RMI server and registers the remote objects. */   public class FileServer  {    public static void main(String args[])     {       /* Sets the RMI security manager. */                      System.setSecurityManager(new RMISecurityManager());       try        {          /* Creates the remote object. */              FileRemote f = new FileRemoteImpl("FServer");          /* Binds the remote object to the RMI registry. */          Naming.rebind("FServer", f);          System.out.println("Object is registered.");          System.out.println("Now server is waiting for client request");         }       catch(Exception e)        {         e.printStackTrace();         System.out.println("FileServer: " + e);       }    } } 
end example
 

Download this Listing .

In the above code:

  • The main() method creates an instance of the RMISecurityManager class. This method sets the security manager to the File Download application using the setSecurityManager() method.

  • The main() method also creates an object of the FileRemoteImpl class and binds the remote object to the RMI registry using the rebind() method.




Java InstantCode. Developing Applications Using Java NIO
Java InstantCode. Developing Applications Using Java NIO
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 55

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net