Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //ADDER.JAVA-----------THE INTERFACE
- import java.rmi.*;
- public interface Adder extends Remote{
- public int add(int x,int y)throws RemoteException;
- public int mul(int xx,int yy)throws RemoteException;
- }
- //MYSERVER------------IMPLEMENTS INTERFACE
- import java.rmi.*;
- import java.rmi.server.*;
- public class MyServer{
- public static void main(String args[]){
- try{
- Adder stub=new AdderRemote();
- Naming.rebind("rmi://localhost:5000/sonoo",stub);
- }catch(Exception e){System.out.println(e);}
- }
- }
- class AdderRemote extends UnicastRemoteObject implements Adder{
- AdderRemote()throws RemoteException{
- super();
- }
- public int add(int x,int y){return x+y;}
- public int mul(int xx,int yy){
- int z;
- z=xx*yy;
- return z;
- }
- }
- //THE CLIENT------------->ACCESSES THE OBJECT FROM THE PORT(rmic MyServer followed by rmiserver xxxx)
- import java.rmi.*;
- public class MyClient{
- public static void main(String args[]){
- try{
- Adder stub=(Adder)Naming.lookup("rmi://localhost:5000/sonoo");
- System.out.println(stub.add(34,4));
- System.out.println(stub.mul(3,4));
- }catch(Exception e){}
- }
- }
Add Comment
Please, Sign In to add comment