Advertisement
Jay_

Server code

Oct 30th, 2013
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.39 KB | None | 0 0
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5. import java.rmi.*;
  6. import java.rmi.registry.LocateRegistry;
  7.  
  8.  
  9. /**
  10.  *
  11.  * @author Jay
  12.  */
  13. public class RMIServer extends java.rmi.server.UnicastRemoteObject
  14.                         implements RemoteServer {
  15.    
  16.     static int port = 1099;
  17.    
  18.    
  19.     //  Constructor for the method
  20.     public RMIServer() throws RemoteException{      
  21.     }
  22.        
  23.     // This is the remote method which is accessible remotely wohoo
  24.     public void helloYou() throws java.rmi.RemoteException
  25.     {
  26.         System.out.println("Hello you!");
  27.     }
  28.    
  29.     public static void main(String[] args)
  30.     {
  31.         try
  32.         {            
  33.             //port should be declared as static int port=1099;
  34.            
  35.             //LocateRegistry belongs to java.rmi.registry, you
  36.             //have to import it
  37.             LocateRegistry.createRegistry(port);
  38.             System.out.println("1. RMI registry ready on port " + port + ".");
  39.             System.out.println("------------------ " );
  40.            
  41.             RMIServer myServer = new RMIServer();
  42.             Naming.rebind("rmi://localhost/RMIServer", myServer);
  43.         }
  44.         catch (Exception e)    
  45.         {
  46.             System.out.println("Exception starting RMI registry:");
  47.             e.getCause();
  48.         }
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement