SL5Exp1

client.java

package exp1;
import java.sql.*;
import java.rmi.*;
import java.io.*;
import java.util.*;
import java.util.Vector.*;
import java.lang.*;
import java.rmi.registry.*;

public class client
{      static String name1,name2,name3;
public static void main(String args[])
{
client c=new client();
BufferedReader b = new BufferedReader(new InputStreamReader(System.in));

int ch;

try {
Registry r1 = LocateRegistry.getRegistry ( “localhost”, 1030);
DBInterface DI=(DBInterface)r1.lookup(“DBServ”);
do
{
System.out.println(“1.send input stings\n2.Display concatenated string \nEnter ur choice”);
ch= Integer.parseInt(b.readLine());
switch(ch)
{
case 1:

System.out.println(” \n Enter first string:”);
name1=b.readLine();

System.out.println(” \n Enter second string:”);
name2=b.readLine();

name3=DI.input(name1,name2);

break;

case 2:
//display
System.out.println(“\n Concatenated String is : “);

int i=0;

System.out.println(” ” +name3+””);

break;

}

}while(ch>0);

}
catch (Exception e)
{
// System.out.println(“ERROR: ” +e.getMessage());
}

}
}

server.java

package exp1;

//RMI Server //
import java.sql.*;
import java.sql.Connection;
import java.rmi.*;
import java.rmi.Naming.*;
import java.rmi.server.*;
import java.rmi.registry.*;
import java.util.Vector;

interface DBInterface extends Remote
{

public String input(String name1,String name2) throws RemoteException;

}

public class server extends UnicastRemoteObject implements DBInterface
{
int flag=0,n,i,j;
String name3;
ResultSet r;

public server() throws RemoteException
{ try
{ System.out.println(“Initializing Server\nServer Ready”);
}
catch (Exception e)
{  System.out.println(“ERROR: ” +e.getMessage());
}
}

public static void main(String[] args)
{ try
{
server rs=new server();
java.rmi.registry.LocateRegistry.createRegistry(1030).rebind(“DBServ”, rs);

}
catch (Exception e)
{
System.out.println(“ERROR: ” +e.getMessage());
}
}

public String input(String name1,String name2)
{
try{

name3=name1.concat(name2);

}
catch (Exception e)
{
System.out.println(“ERROR: ” +e.getMessage());
}
return name3;
}

}


Archives