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);
}
}
}
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);
}
}
}
http://www.kidsfront.com/ make yourself full of knowledge about any topic just click on the site grab the info
ReplyDelete