Ashies

RMI

May 2nd, 2017
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.15 KB | None | 0 0
  1. //ADDER.JAVA-----------THE INTERFACE
  2.  
  3. import java.rmi.*;  
  4. public interface Adder extends Remote{  
  5. public int add(int x,int y)throws RemoteException;  
  6. public int mul(int xx,int yy)throws RemoteException;  
  7. }  
  8.  
  9. //MYSERVER------------IMPLEMENTS INTERFACE
  10.  
  11. import java.rmi.*;  
  12. import java.rmi.server.*;  
  13.  
  14. public class MyServer{  
  15. public static void main(String args[]){  
  16. try{  
  17. Adder stub=new AdderRemote();  
  18. Naming.rebind("rmi://localhost:5000/sonoo",stub);  
  19. }catch(Exception e){System.out.println(e);}  
  20. }  
  21. }  
  22.  
  23.  
  24. class AdderRemote extends UnicastRemoteObject implements Adder{  
  25. AdderRemote()throws RemoteException{  
  26. super();  
  27. }  
  28.  
  29.  
  30. public int add(int x,int y){return x+y;}
  31. public int mul(int xx,int yy){
  32.     int z;
  33.     z=xx*yy;
  34.     return z;
  35. }
  36. }
  37.  
  38.  
  39.  
  40.  
  41. //THE CLIENT------------->ACCESSES THE OBJECT FROM THE PORT(rmic MyServer followed by rmiserver xxxx)
  42.  
  43. import java.rmi.*;  
  44. public class MyClient{  
  45. public static void main(String args[]){  
  46. try{  
  47. Adder stub=(Adder)Naming.lookup("rmi://localhost:5000/sonoo");  
  48. System.out.println(stub.add(34,4));  
  49. System.out.println(stub.mul(3,4));  
  50. }catch(Exception e){}  
  51. }  
  52. }
Add Comment
Please, Sign In to add comment