Showing posts with label NETWORK OPERATING SYSTEMS. Show all posts
Showing posts with label NETWORK OPERATING SYSTEMS. Show all posts

Sunday, May 31, 2015

NETWORK OPERATING SYSTEMS

AIM:
            To write a java program for network operating systems


ALGORITHM:


Step 1:         Start the program

Interface program
Step 2:         Create an interface ReceiveMessageInterface which extends Remote class
Step 3:         Declare method receiveMessage inside interface


Server Program
Step 4:         Create class RmiServer which extends UnicastRemoteObject which again extends the ReceiveMessageInterface
Step 5:         Define the method receiveMessage which get parameter x
Step 6:         Declare a Random object which is used to get random integers
Step 7:         Using the value of x get the Random number one by one and store it in val[i]
Step 8:         Define a constructor RmiServer in that get the local address of the Server by using InetAddress.getLocalHost()
Step 9:         Declare a port and register it in the registry object
Step 10:     Using Rebind method we register the port and a string “rmiserver” into the rmiregistry table
Step 11:     Create a object using RmiServer so that the Constructor will be initialized automatically



Client program
Step 12:     Create class RmiClient
Step 13:     Declare an object rmiServer for ReceiveMessageInterface
Step 14:     Get the server’s local address and the port in command line arguments
Step 15:     Locate the registry object using the server port
Step 16:     Using registry object call the method lookup of the server string “rmiserver” by casting the interface which is already defined
Step 17:     Now using the rmiServer object call the method receiveMessage and receive all random number one by one from the server
Step 18:     End of programs




PROGRAM:-

ReceiveMessageInterface:


import java.rmi.*;
public interface ReceiveMessageInterface extends Remote
{
   public int [] receiveMessage(int x) throws RemoteException;
}


RmiClient.java:

import java.io.*;
import java.rmi.*;
import java.rmi.registry.*;
import java.net.*;

public class RmiClient
{
    static public void main(String args[])throws IOException
    {
       ReceiveMessageInterface rmiServer;
       Registry registry;
       String serverAddress=args[0];
       String serverPort=args[1];
       int no;
       no=Integer.parseInt(args[2]);
       int rval[]=new int[no];
       System.out.println("sending "+no+" to "+serverAddress+":"+serverPort);
       try{
           registry=LocateRegistry.getRegistry(serverAddress,(new Integer(serverPort)).intValue());
           rmiServer=(ReceiveMessageInterface)(registry.lookup("rmiServer"));
           rval=rmiServer.receiveMessage(no);
           for(int i=0;i<no;i++)
           System.out.println(rval[i]);
          }
       catch(RemoteException e)
       {
            e.printStackTrace();
       }
       catch(NotBoundException e)
       {
        e.printStackTrace();
       }
    }
}