Ad Code

Responsive Advertisement

Ticker

6/recent/ticker-posts

Create a RMI application where the client will handshake with the server by invoking the remote method public void sayHello() where client and server are on different hosts in the same network

Create a distributed application using RMI where the client will handshake with the server by invoking the remote method public void sayHello() where client and server are on different hosts in the same network.

Java Program - 

RemoteInterface.java - 

package com.gpm.ex3;

import java.rmi.RemoteException;

import java.rmi.Remote;


public interface RemoteInterface extends Remote {

    public void SayHello() throws RemoteException;

}

Servant.java - 

package com.gpm.ex3;

import java.rmi.Remote;

import java.rmi.RemoteException;

import java.rmi.server.UnicastRemoteObject;


public class Servant extends UnicastRemoteObject implements RemoteInterface {

    public Servant() throws RemoteException

    {

        super();

    }

    public void SayHello() throws RemoteException

    {

        System.out.println("Hello Server");

    }

}


Server.java - 

package com.gpm.ex3;

import java.rmi.RemoteException;

import java.rmi.registry.Registry;

import java.rmi.registry.LocateRegistry;


public class Server {
    
    public static void main(String args[]) throws RemoteException
    
    {
        Registry registry = LocateRegistry.createRegistry(6000);
        
        registry.rebind("hello", new Servant());
    }

}

Client.java - 

package com.gpm.ex3;

import java.net.MalformedURLException;

import java.rmi.Naming;

import java.rmi.NotBoundException;

import java.rmi.RemoteException;


public class Client {
    public static void main(String args[]) throws NotBoundException, MalformedURLException, RemoteException
    {
        RemoteInterface helloInterface = (RemoteInterface)Naming.lookup("rmi://192.168.1.14:6000/hello");
        helloInterface.SayHello();
    }
}


Output - 


Post a Comment

0 Comments

Ad Code

Responsive Advertisement