Server business interface
Public interface Biz extends Remote {
Public String aloha () throws RemoteException;
}
Server business implementation
Public class BizImpl extends UnicastRemoteObject implements Biz {
Private static final long serialVersionUID =-8559392326593037120L;
Public BizImpl () throws RemoteException {
Super ();
}
@ Override
Public String aloha () throws RemoteException {
Return "Aloha Baby .";
}
}
Remote implementation name for Server Registration
Public class Server {
Public Server (){
Try {
Biz bis = new BizImpl ();
// Style-1
Registry registry = LocateRegistry. createRegistry (RMIParameter. PORT );
Registry. rebind (RMIParameter. NAME, bis); // replace existing binding name
// Style-2
// Java. rmi. Naming. rebind (RMIParameter. NAME, bis); // replace existing binding name
} Catch (Exception e ){
E. printStackTrace ();
}
}
Public static void main (String args []) {
New Server ();
}
}
Style-2 needs to specify a Policy file or run rmiregistry
Java-Djava. security. policy = folder_x/rmi/policy_file creative. fire. rmi. Server
Policy file content:
Grant {
Permission java.net. SocketPermission "localhost: 9527", "connect, resolve ";
};
Run rmiregistry to modify jre/lib/security/java. policy under the JDK directory.
Rmiregistry (linux)
Start rmiregistry (windows)
Allow anyone (targets) to do anything (actions ):
Grant {
Permission java. security. AllPermission "","";
};
OR
Grant {
Permission java. security. AllPermission;
};
Client piling call
Public class Client {
Public static void main (String args []) {
Try {
Biz bis = (Biz) Naming. lookup (RMIPREFIX + PORT + NAME );
System. out. println (bis. aloha ());
} Catch (Exception e ){
E. printStackTrace ();
}
}
}