Wednesday 26 June 2013

RMI implementation program

Hello.java

import java.rmi.*;
public interface Hello extends Remote
{
String sayHello(String s) throws RemoteException;

}


HelloImpl.java

import java.rmi.*;
import java.rmi.server.*;
public class HelloImpl extends UnicastRemoteObject implements Hello
{
private int i;
public HelloImpl() throws RemoteException
{
System.out.println("Object created");
}
public String sayHello(String s) throws RemoteException
{
i++;
return "Hello " + s + " Yours is " + i + " request.";
}

}

HelloServer.java

import java.rmi.*;
import java.rmi.registry.*;
public class HelloServer
{
public static void main(String[] args)
{
try
{
LocateRegistry.createRegistry(1112);
HelloImpl r = new HelloImpl();
Naming.rebind("//127.0.0.1:1112/value", r);
System.out.println(" Object ready");
}
catch (Exception e)
{
System.out.println(e);
}
}

}

HelloClient.java

import java.rmi.*;
public class HelloClient
{
public static void main(String[] args)
{
try
{
Remote r = Naming.lookup("//127.0.0.1:1112/value");
Hello i = (Hello) r;
String result = i.sayHello(args[0]);
System.out.println( "From Server: " + result);
}
catch (Exception e)
{
System.out.println(e);
}
}

}

Best geography books for UPSC prelims, mains

This post is intended to clear the confusion that prevails among the aspirants over how to prepare for UPSC geography and the best books f...