Java remote method invocation: Difference between revisions

Content deleted Content added
m Task 70: Update syntaxhighlight tags - remove use of deprecated <source> tags
fix some broken refs
Line 43:
 
try { //special exception handler for registry creation
LocateRegistry.createRegistry(1099);
System.out.println("java RMI registry created.");
} catch (RemoteException e) {
Line 68:
public interface RmiServerIntf extends Remote {
String getMessage() throws RemoteException;
}
</syntaxhighlight>
 
'''<code>RmiClient</code> class''' &mdash; this is the client which gets the reference (a proxy) to the remote object living on the server and invokes its method to get a message. If the server object implemented java.io.Serializable instead of java.rmi.Remote, it would be serialized and passed to the client as a value.<ref>[http{{cite web |last1=Wilson |first1=M. Jeff |date=2000-11-10 |df=mdy |url=https://www.javaworldinfoworld.com/javaworldarticle/jw2076234/get-11smart-2000/jwwith-1110proxies-and-smartproxyrmi.html |title=Get smart with proxies and RMI - |work=[[JavaWorld]] |accessdate=2020-07-18}}</ref>
 
<syntaxhighlight lang=java>
import java.rmi.Naming;
 
public class RmiClient {
public static void main(String args[]) throws Exception {
RmiServerIntf server = (RmiServerIntf)Naming.lookup("//localhost/RmiServer");
System.out.println(server.getMessage());
}
}