To create a distributed application to download various files from various servers us
#1

Aim: To create a distributed application to download various files from various servers using RMI
Algorithm:
1. Create four files – file interface, file implementation, file client and fileserver
2. In the file interface, class specify the prototype of the method that is to be implemented in the file implementation class
3. In the file implementation class, specify the implementation coding for the method defined earlier (download file[])
4. Try to read the contents of a file in this class
5. In the fileclient class try to write some contents into a file
6. In the fileserver class, try to register / bind the methods with the rmiregistry
7. Compile all the files and execute as specified to get the desired output.
Program
FileInterface.java
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface FileInterface extends Remote {
public byte[] downloadFile(String fileName) throws
RemoteException;
Code:
}

FileImpl.java

import java.io.*;
import java.rmi.*;
import java.rmi.server.UnicastRemoteObject;

public class FileImpl extends UnicastRemoteObject
  implements FileInterface {
   private String name;
   public FileImpl(String s) throws RemoteException{
      super();
      name = s;
   }

   public byte[] downloadFile(String fileName){
      try {
         File file = new File(fileName);
         byte buffer[] = new byte[(int)file.length()];
         BufferedInputStream input = new
      BufferedInputStream(new FileInputStream(fileName));
         input.read(buffer,0,buffer.length);
         input.close();
         return(buffer);
      } catch(Exception e){
         System.out.println("FileImpl: "+e.getMessage());
         e.printStackTrace();
         return(null);
      }
   }
}

FileServer.java
import java.io.*;
import java.rmi.*;

public class FileServer {
   public static void main(String argv[]) {
         try {
         FileInterface fi = new FileImpl("FileServer");
         Naming.rebind("//127.0.0.1/FileServer", fi);
      } catch(Exception e) {
         System.out.println("FileServer: "+e.getMessage());
         e.printStackTrace();
      }
   }
}

FileClient.java
import java.io.*;
import java.rmi.*;

public class FileClient{
   public static void main(String argv[]) {
      if(argv.length != 2) {
        System.out.println("Usage: java FileClient fileName machineName");
        System.exit(0);
      }
      try {
         String name = "//" + argv[1] + "/FileServer";
         FileInterface fi = (FileInterface) Naming.lookup(name);
         byte[] filedata = fi.downloadFile(argv[0]);
System.out.println(“enter the file to download”);
BufferedReader br = new BufferedReader(new InputStreamReader(system.in));
String newname = br.readLine();
         File file = new File(newname);
         BufferedOutputStream output = new
           BufferedOutputStream(new FileOutputStream(file.getName()));
         output.write(filedata,0,filedata.length);
         output.flush();
         output.close();
      } catch(Exception e) {
         System.err.println("FileServer exception: "+ e.getMessage());
         e.printStackTrace();
      }
   }
}
Execution
Server folder [interface.java,fileimpl.java,file server.java]
1. Compile all the java program using (javac filename.java)
2. enter the (start rmiregistry) in command line
3. create stub and skeleton using (rmic FileImpl)
4.create one file i.e a.txt in server folder
5. Run the server using (java FileServer)
Client folder[file interface.java,fileclient.java,copy the stub and skeleton from server folder and paste it in client folder]
1. Compile all the java program using (javac filename.java)
(The next contains two parameters First is the text file created by the user second is machine IP Address)
2. Run the Client using (java FileClient a.txt 192.168.0.154)
7. next step you will give the file name to download the file (Enter the file name to download : b.txt)
8. a.txt and b.txt contains the same content.
Reply

Important Note..!

If you are not satisfied with above reply ,..Please

ASK HERE

So that we will collect data for you and will made reply to the request....OR try below "QUICK REPLY" box to add a reply to this page
Popular Searches: create, collection of various documents used in bank, create automobile, various departments of sbi, various phases in student info system, filename with, analysis and simulation of the various generators used in wind systems ppt,

[-]
Quick Reply
Message
Type your reply to this message here.

Image Verification
Please enter the text contained within the image into the text box below it. This process is used to prevent automated spam bots.
Image Verification
(case insensitive)

Possibly Related Threads...
Thread Author Replies Views Last Post
  How to create a report in Microsoft Access? smart paper boy 0 1,152 29-07-2011, 12:16 PM
Last Post: smart paper boy
  How to create a query in Microsoft Access? smart paper boy 0 1,099 29-07-2011, 12:14 PM
Last Post: smart paper boy
  How to create tables in MS ACCESS ? smart paper boy 0 1,226 29-07-2011, 12:14 PM
Last Post: smart paper boy
  what are various types of TRANSMISSION MEDIA? smart paper boy 0 2,374 29-07-2011, 12:12 PM
Last Post: smart paper boy
  . What is a network? what are its various types? smart paper boy 0 1,065 29-07-2011, 12:11 PM
Last Post: smart paper boy
  What is internet and what are its various applications? smart paper boy 0 1,718 29-07-2011, 12:08 PM
Last Post: smart paper boy
  what is IT and its application? smart paper boy 0 972 29-07-2011, 12:07 PM
Last Post: smart paper boy
  To develop an Activex control document and perform the various file operations smart paper boy 0 1,181 21-07-2011, 09:45 AM
Last Post: smart paper boy
  To create a Java Bean to draw various graphical shapes and display it using smart paper boy 0 1,931 21-07-2011, 09:40 AM
Last Post: smart paper boy
  Create a view on the Client_master table for administration department. smart paper boy 0 1,180 09-07-2011, 10:43 AM
Last Post: smart paper boy

Forum Jump: