Remote Method Invocation

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

KUPPUSAMY M.

TECH(1ST YEAR)
REG NO; 20394012

Remote Method Invocation

DATA BASE S
import java.rmi.Remote;

import java.rmi.RemoteException;

public interface Hello extends Remote

void printMsg() throws RemoteException;

IMPLEMENTATION
import java.rmi.*;

import java.rmi.server.*;

import java.io.*;

import java.net.*;

public class Impl implements Hello

public void printMsg()

System.out.println("This is an example RMI program");

SERVER
import java.rmi.registry.Registry;

import java.rmi.registry.LocateRegistry;

import java.rmi.RemoteException;

import java.rmi.server.UnicastRemoteObject;

public class Server extends Impl


KUPPUSAMY M.TECH(1ST YEAR)
REG NO; 20394012

public Server() {}

public static void main(String args[])

try

Impl obj = new Impl();

Hello stub = (Hello) UnicastRemoteObject.exportObject(obj, 0);

Registry registry = LocateRegistry.getRegistry();

registry.bind("Hello", stub);

System.err.println("Server ready");

catch (Exception e) {

System.err.println("Server exception: " + e.toString());

e.printStackTrace();

CLIENT
import java.rmi.registry.LocateRegistry;

import java.rmi.registry.Registry;

public class Client

private Client() {}

public static void main(String[] args)

try

{
KUPPUSAMY M.TECH(1ST YEAR)
REG NO; 20394012

Registry registry = LocateRegistry.getRegistry(null);

Hello stub = (Hello) registry.lookup("Hello");

stub.printMsg();

System.out.println("Remote method invoked");

catch (Exception e)

System.err.println("Client exception: " + e.toString());

e.printStackTrace();

You might also like