Remote invocation tool code in java

by barkkathulla 2012-09-22 11:45:54

import java.rmi.registry.*;

public class RmiServer extends UnicastRemoteObject
implements RmiServerIntf {
public static final String MESSAGE = "Hello world";

public RmiServer() throws RemoteException {
}

public String getMessage() {
return MESSAGE;
}


public static void main(String args[]) {
System.out.println("RMI server started");

// Create and install a security manager
if (System.getSecurityManager() == null) {
System.setSecurityManager(new RMISecurityManager());
System.out.println("Security manager installed.");
} else {
System.out.println("Security manager already exists.");
}

try { //special exception handler for registry creation
LocateRegistry.createRegistry(1099);
System.out.println("java RMI registry created.");
} catch (RemoteException e) {
//do nothing, error means registry already exists
System.out.println("java RMI registry already exists.");
}

try {
//Instantiate RmiServer
RmiServer obj = new RmiServer();

// Bind this object instance to the name "RmiServer"
Naming.rebind("//localhost/RmiServer", obj);

System.out.println("PeerServer bound in registry");
} catch (Exception e) {
System.err.println("RMI server exception:" + e);
e.printStackTrace();
}
}
}
909
like
0
dislike
0
mail
flag

You must LOGIN to add comments